-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphp.txt
390 lines (254 loc) · 8.55 KB
/
php.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
>>>>> PHP<<<<<<<<
---------------------------------------
Keys:
password hash, password identify, header, php installation on ubuntu,
php mysql connection,date
----------------------------------------
----------------------------------------
----------------------------------------
parse_url( , )
explode()
parse_str( , )
header_remove()
is_array()
count()
strtoupper()
json_encode()
exit()
Flags:
PHP_URL_PATH
-------------------------------------------
-------------------------------------------
>> Password Hash <<
//Content Type
//-----Content Types In PHP--------------
//header("Content-Type:application/json");
//header("Content-Type:application/pdf");
//header("Content-Type:image/png");
//header("Content-Type:video/mp4");
//header('Access-Control-Allow-Origin:*')
//header('Access-Control-Allow-Methods: GET, POST')
//header('Access-Control-Allow-Headers: ')
//-----Content Types In PHP -------------
//Password Hashing
//echo md5("Ajay Sisaudiya"); echo "<br>";
//echo sha1("Ajay Sisaudiya"); echo "<br>";
//echo crypt("Ajay Sisaudiya",10); echo "<br>";
//echo base64_encode("Ajay Sisaudiya"); echo "<br>";
//echo base64_decode("QWpheSBTaXNhdWRpeWE="); echo "<br>";
//echo password_hash("Ajay Sisaudiya",PASSWORD_DEFAULT); echo "<br>";
//echo password_hash("Ajay Sisaudiya", PASSWORD_BCRYPT ); echo "<br>";
//echo password_hash("Ajay Sisaudiya", PASSWORD_ARGON2I ); echo "<br>";
//echo password_hash("Ajay Sisaudiya", PASSWORD_ARGON2ID ); echo "<br>";
//password_verify() - Verifies that a password matches a hash
//crypt() - One-way string hashing
//» userland implementation
//sodium_crypto_pwhash_str() - Get an ASCII-encoded hash
-------------------------------------------------------------------------
//Adding 7 days to today's date
$dt = date("Y-m-d");
echo $startDate = date( "Y-m-d", strtotime( "$dt +0 day" ) ); // PHP: 2023-03-31
echo $endDate = date( "Y-m-d", strtotime( "$dt +7 day" ) ); // PHP: 2023-04-07
//Diff two dates
function dateDiffInDays($date1, $date2)
{
// Calculating the difference in timestamps
$diff = strtotime($date2) - strtotime($date1);
// 1 day = 24 hours
// 24 * 60 * 60 = 86400 seconds
return abs(round($diff / 86400));
}
// Start date
$date1 = "17-09-2018";
// End date
$date2 = "31-09-2018";
// Function call to find date difference
$dateDiff = dateDiffInDays($date1, $date2);
// Display the result
printf("Difference between two dates: "
. $dateDiff . " Days ");
Output:
Difference between two dates: 14 Days
--------------------------------------------------------------------------
# PHP Installation On Ubuntu
##### Configure PHP on a Debian or Ubuntu instance
Step 1 — Add the repository
You must first run the following command to add a repository before installing PHP.
sudo add-apt-repository ppa:ondrej/php
Step 2 — Update
Run the following to update your list of packages.
sudo apt update
Step 3 — Install PHP
You have the choice to install PHP as a module or FPM.
Installing as a PHP module
Run the following commands to install and load PHP.
sudo apt install php8.0 libapache2-mod-php8.0
Installing as FPM
Run the following commands to install, enable, and load PHP-FPM.
sudo apt install php8.0-fpm libapache2-mod-fcgid
Step 4 — Confirm PHP is installed
Finally, run the following command to view the version you installed.
php -v
Install modules (extensions)
After PHP is installed, you can proceed with installing any modules (also called extensions) needed.
View available modules you can install
This command lists all modules available for you to install.
sudo apt search php8.0-*
Install a module
After locating the correct name of a module, you can install it using the following command.
sudo apt install php8.0-sqlite3
You can also install several modules at once. This assumes the module names start with php8.0-.
sudo apt install php8.0-{mysql,imap,zip}
View modules currently loaded
The following command lists all modules currently loaded by PHP.
php -m
Configuration Files
There are a few configuration files for PHP that are used for the CLI and the Apache modules (or PHP-FPM) specifically. Change <version> to your specific version of PHP.
/etc/php/cli/<version>/php.ini
The primary configuration file for PHP when executed from the CLI.
/etc/php/<version>/apache2/php.ini
The primary configuration file for PHP when run from the Apache module.
/etc/php/<version>/fpm/php.ini
The primary configuration file for PHP when run from as PHP-FPM.
----------------------------------------------
# PHP Mysql Connection:
## Create MySql Table
Example:
CREATE TABLE Persons (
personID int,
lastName varchar(255),
firstName varchar(255),
address varchar(255),
city varchar(255)
);
INSERT INTO table_name
VALUES (value1, value2, value3, ...);
SELECT * FROM table_name;
Example (MySQLi Procedural):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Example (MySQLi Object-Oriented):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Example (PDO):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
?>
Example (MySQLi Procedural):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
Example (MySQLi Object-oriented):
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Example (PDO):
<?php
echo "<table style='border: solid 1px black;'>";
echo "<tr><th>Id</th><th>Firstname</th><th>Lastname</th></tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT id, firstname, lastname FROM MyGuests");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
-------------------------------------------
-------------------------------------------