-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtips.php
88 lines (80 loc) · 2.21 KB
/
tips.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
<?php
require ('config.php');
/**
* ajaxResponse
* status 0 for error ,1 for query success
* @param mixed $status
* @param array $info
* @access public
* @return json
*/
function ajaxResponse($status, array $info)
{
if (isset($info['count'])) {
$arr = array(
'status' => $status,
'info' => array(
'count' => $info['count'],
'time' => $info['time']
)
);
} else {
$arr = array(
'status' => $status,
'info' => $info,
);
}
echo json_encode($arr);
exit;
}
// validate autoKey
if (!isset($_POST['key']) || $_POST['key'] != $authKey) {
ajaxResponse(0, array('info' => 'error'));
}
if (!isset($_POST['url'])) {
ajaxResponse(0, array('info' => 'error'));
}
$url = $_POST['url'];
$conn = mysql_connect($mysqlHost, $mysqlUser, $mysqlPwd);
if (!$conn) {
exit('Cannot connect to mysql '.mysql_errno());
}
mysql_select_db('google');
mysql_query("set names 'utf8'");
//exclude url
$sqlExclude = "select count(*) as num from excludeurl where url = '$url'";
$resExclude = mysql_query($sqlExclude);
while ($row = mysql_fetch_assoc($resExclude)) {
if ($row['num'] > 0) {
ajaxResponse(2, array('info' => 'exlucde url'));
}
}
//exclude domain
$res = parse_url($url);
if (!isset($res['host'])) {
ajaxResponse(0, array('info' => 'bad request ! url is '.$url));
}
$domain = $res['host'];
$sqlExclude = "select count(*) as num from excludedomain where domain = '$domain'";
$resExclude = mysql_query($sqlExclude);
while ($row = mysql_fetch_assoc($resExclude)) {
if ($row['num'] > 0) {
ajaxResponse(2, array('info' => 'exclude domain'));
}
}
$timeFile = date("Y-m-d H:i:s", time()-300);
$sqlHistory = "select time from chromeurllog where url ='$url' and time < '$timeFile'";
$resHistory = mysql_query($sqlHistory);
$res = array();
while ($row = mysql_fetch_assoc($resHistory)) {
$res[] = $row['time'];
}
$count = count($res);
$showRes = array(
'first' => $res[0],
'last' => array_pop($res)
);
ajaxResponse(1, array(
'count' => $count,
'time' => $showRes,
));