forked from soxft/UrlShorting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
158 lines (158 loc) · 4.6 KB
/
api.php
File metadata and controls
158 lines (158 loc) · 4.6 KB
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
<?php
include('./app/record.php');
include('./app/time.php');
include('./config.php');
if (empty($_GET['ip'])) {
include('./app/ip.php');
} else {
$ip = $_GET['ip'];
}
$domain = $_GET['d'];
$passmessage = $_GET['m'];
$domain = str_replace("||","&",$domain);
$passmessage = str_replace("||","&",$passmessage);
//替换原网址中的&&防止出错
$check1 = "SELECT *FROM `ban` where `content`='$ip';";
$count1 = mysqli_query($conn,$check1);
$arr1 = mysqli_fetch_assoc($count1);
$type = $arr1['type'];
if(!empty($type)){
$data = array(
'code' => '1003',
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
} //检索用户ip是否被封禁
if (empty($domain) && empty($passmessage)) {
//检测是否有输入
$data = array(
'code' => '1001',
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
}
//判断正式开始
if (!empty($domain) && empty($passmessage)) {
//判断为短域
//判断是包含http://或https://
if (strpos($domain,'http://') !== false) {} elseif (strpos($domain,'https://') !== false) {} else {
$domain = 'http://' . $domain;
}
if (strlen($domain) > 200) {
$data = array(
'code' => '1002',
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
}
@$comd = "SELECT * FROM `information` WHERE `information`='$domain'";
@$count = mysqli_query($conn,$comd);
@$arr1 = mysqli_fetch_assoc($count);
@$shorturl = $arr1['shorturl'];
//如果已存在则
if (!empty($shorturl)) {
$data = array(
'code' => '200',
'shorturl' => $url . $shorturl,
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
}
//如果不存在则
//随机生成大小写字母
rese:
$shorturl = null;
$max = strlen($strPol)-1;
for ($i = 0;$i < $pass;$i++) {
$shorturl.= $strPol[rand(0,$max)];
}
//检测随机生成的是否有重复
@$comd1 = "SELECT * FROM `information` WHERE shorturl='$shorturl'";
@$count1 = mysqli_query($conn,$comd1);
@$arr2 = mysqli_fetch_assoc($count1);
@$domain1 = $arr2['information'];
if (empty($domain1)) {
$comd1 = "insert into `information` values('$domain','$shorturl','shorturl','$time','$ip');";
$go = mysqli_query($conn,$comd1);
$data = array(
'code' => '200',
'shorturl' => $url . $shorturl,
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
} else {
goto rese;
}
}
if (empty($domain)&&!empty($passmessage)) {
//判断为密语
if (strlen($passmessage) > 200) {
$data = array(
'code' => '1002',
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
}
@$comd = "SELECT * FROM `information` WHERE `information`='$passmessage'";
@$count = mysqli_query($conn,$comd);
@$arr1 = mysqli_fetch_assoc($count);
@$shorturl = $arr1['shorturl'];
//如果已存在则
if (!empty($shorturl)) {
$data = array(
'code' => '200',
'shorturl' => $url . $shorturl,
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
}
//如果不存在则
//随机生成大小写字母
rese2: //安全起见判断是否有重复短域名id
$shorturl = null;
$max = strlen($strPol)-1;
for ($i = 0;$i < $pass;$i++) {
$shorturl.= $strPol[rand(0,$max)];
}
//检测随机生成的是否有重复
@$comd1 = "SELECT * FROM `information` WHERE shorturl='$shorturl'";
@$count1 = mysqli_query($conn,$comd1);
@$arr2 = mysqli_fetch_assoc($count1);
@$information = $arr2['information'];
if (empty($information)) {
$comd1 = "insert into `information` values('$passmessage','$shorturl','passmessage','$time','$ip');";
$go = mysqli_query($conn,$comd1);
$data = array(
'code' => '200',
'shorturl' => $url . $shorturl,
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
exit;
} else {
goto rese2;
}
} else {
$data = array(
'code' => '1003',
);
$data_json = json_encode($data);
header('Content-type:text/json');
echo $data_json;
}
?>