-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.php
167 lines (73 loc) · 2.22 KB
/
common.php
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
<?php
// 定义上传上来的图像文件存放的目录,注意是相对目录
define("UPLOAD_IMGS_PATH", "upload_imgs/");
// 上传文件的函数
function upload($name, $destDir)
{
if(empty($_FILES[$name])) return '';
$uploadname = basename($_FILES[$name]['name']);
$uploaddir = realpath($destDir) . '/';
$uploadfile = $uploaddir . $uploadname;
if(file_exists($uploadfile)) {
$uploadname .= rand();
$uploadfile = $uploaddir . $uploadname;
}
if (move_uploaded_file($_FILES[$name]['tmp_name'], $uploadfile)) {
return $uploadname;
}
return '';
}
function db_connect()
{
$db = @new mysqli("127.0.0.1", "developer", "123456", "bbs");
if (!$db)
return false;
return $db;
}
function reformat_date($datetime)
{
// 格式化日期时间
list($year, $month, $day, $hour, $min, $sec) = split( '[: -]', $datetime );
return "{$year}年{$month}月{$day}日 $hour:$min:$sec";
}
function makeIns4SQL($arr, $type='int')
{
if(empty($arr)) return '';
$ins = '';
foreach($arr as $value) {
if($type == 'int')
$ins .= "$value,";
else
$ins .= "'$value',";
}
$ins{strlen($ins)-1} = ' '; //移除末尾的','号
return $ins;
}
// 检查客户端提交的数据中是否含有非法字符
function checkIllegalWord ()
{
// 定义不允许提交的SQL命令及关键字
$words = array();
$words[] = "add";
$words[] = "count";
$words[] = "create";
$words[] = "delete";
$words[] = "drop";
$words[] = "from";
$words[] = "grant";
$words[] = "insert";
$words[] = "select";
$words[] = "truncate";
$words[] = "update";
$words[] = "use";
// 判断提交的数据中是否存在以上关键字, $_REQUEST中含有所有提交数据
foreach($_REQUEST as $strGot) {
$strGot = strtolower($strGot); // 转为小写
if (in_array($strGot, $words)) {
echo "您输入的内容含有非法字符!";
exit; // 退出运行
}
}// foreach
}
checkIllegalWord(); // 检查非法字符
?>