-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp.json
139 lines (139 loc) · 3.34 KB
/
php.json
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
{
"PrettyArray": {
"prefix": "beauty",
"body": [
"print(`<pre>`.print_r($array_data,true).`</pre>`);"
],
"description": "Pretty print array"
},
"amime": {
"prefix": "amime",
"body": [
"if ($$_SERVER['REMOTE_ADDR'] == '') {",
" ",
"}"
],
"description": "Check if IP address matches"
},
"ConnectMySQL": {
"prefix": "connectdb",
"body": [
"<?php",
"$host = 'localhost';",
"$db_name = 'your_db_name';",
"$user = 'your_db_user';",
"$password = 'your_db_password';",
"$charset = 'utf8mb4';",
"",
"$dsn = \"mysql:host=$host;dbname=$db_name;charset=$charset\";",
"$options = [",
" PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,",
" PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,",
" PDO::ATTR_EMULATE_PREPARES => false,",
"];",
"",
"try {",
" $pdo = new PDO($dsn, $user, $password, $options);",
"} catch (PDOException $e) {",
" throw new PDOException($e->getMessage(), (int)$e->getCode());",
"}",
"?>"
],
"description": "Connect to MySQL database with PDO"
},
"ExecuteSQL": {
"prefix": "execsql",
"body": [
"<?php",
"$query = 'SELECT * FROM your_table';",
"$stmt = $pdo->query($query);",
"",
"while ($row = $stmt->fetch()) {",
" echo $row['column_name'] . '<br>';",
"}",
"?>"
],
"description": "Execute an SQL query"
},
"ExecuteSQLWithParams": {
"prefix": "execsqlparam",
"body": [
"<?php",
"$query = 'SELECT * FROM your_table WHERE column_name = :value';",
"$stmt = $pdo->prepare($query);",
"$stmt->execute(['value' => $value]);",
"",
"while ($row = $stmt->fetch()) {",
" echo $row['column_name'] . '<br>';",
"}",
"?>"
],
"description": "Execute an SQL query with parameters"
},
"IncludePHP": {
"prefix": "includephp",
"body": [
"<?php",
"include 'path/to/your/file.php';",
"?>"
],
"description": "Include a PHP file"
},
"RedirectPage": {
"prefix": "redirect",
"body": [
"<?php",
"header('Location: your_page.php');",
"exit;",
"?>"
],
"description": "Redirect to another page"
},
"CreateSession": {
"prefix": "createsession",
"body": [
"<?php",
"session_start();",
"",
"$_SESSION['key'] = 'value';",
"?>"
],
"description": "Create a session"
},
"SanitizeInput": {
"prefix": "sanitize",
"body": [
"<?php",
"function sanitizeInput($input) {",
" $input = trim($input);",
" $input = stripslashes($input);",
" $input = htmlspecialchars($input);",
" return $input;",
"}",
"?>"
],
"description": "Sanitize an input"
},
"CreateHashedPassword": {
"prefix": "hashpwd",
"body": [
"<?php",
"$hashed_password = password_hash($password, PASSWORD_DEFAULT);",
"?>"
],
"description": "Create a hashed password"
},
"VerifyHashedPassword": {
"prefix": "verifypwd",
"body": [
"<?php",
"if (password_verify($password, $hashed_password)) {",
" // Password correct",
"} else {",
" // Password incorrect",
"}",
"?>"
],
"description": "Verify a hashed password"
}
}