wl.php
1.97 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
<?php
$now = time();
/**
* 获取客户端ip
* @return String
*/
function getClientIp() {
$ip = '';
if (getenv ( "HTTP_CLIENT_IP" ) && strcasecmp ( getenv ( "HTTP_CLIENT_IP" ), "unknown" )) {
$ip = getenv ( "HTTP_CLIENT_IP" );
} elseif (getenv ( "HTTP_X_FORWARDED_FOR" ) && strcasecmp ( getenv ( "HTTP_X_FORWARDED_FOR" ), "unknown" )) {
$ip = getenv ( "HTTP_X_FORWARDED_FOR" );
} elseif (getenv ( "REMOTE_ADDR" ) && strcasecmp ( getenv ( "REMOTE_ADDR" ), "unknown" )) {
$ip = getenv ( "REMOTE_ADDR" );
} elseif (isset ( $_SERVER ["REMOTE_ADDR"] ) && $_SERVER ["REMOTE_ADDR"] && strcasecmp ( $_SERVER ['REMOTE_ADDR'], "unknown" )) {
$ip = $_SERVER ["REMOTE_ADDR"];
} else {
$ip = "0.0.0.0";
}
return $ip;
}
function getPostData($dataName)
{
return isset($_POST[$dataName]) ? $_POST[$dataName] : "";
}
$localIp = getClientIp();
$ip = getPostData('ip');
$start_time = getPostData('start_time');
$end_time = getPostData('end_time');
$note = getPostData('note');
$sql = "";
if(!empty($ip)) {
$start_time = strtotime($start_time);
$end_time = strtotime($end_time);
$intIp = ip2long($ip);
$localIp = $ip;
$sql = "insert into `yoho_portal`.`user_whitelist`(`ip`, `create_time`,`start_time`,`end_time`,`note`) values($intIp, $now, $start_time, $end_time, '$note') on duplicate key update `start_time`=$start_time,`end_time`=$end_time,`note`='$note'";
}
?>
<html>
<header>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</header>
<body>
<form action="#" method="post">
IP:<input type="text" name="ip" value="<?php print $localIp;?>"/> (*如果不填则为本地IP)<br/>
起始时间:<input type="text" name="start_time" id="start_time" value="<?php print date('Y-m-d H:i:s', $now);?>"/> <br/>
结束时间:<input type="text" name="end_time" id="end_time" value="<?php print date('Y-m-d H:i:s', $now + 86400);?>"/> <br/>
备注:<input type="text" name="note" /> <br/>
<input type="submit" value="提交"/>
</form>
<br/>
<?php print $sql;?>
</body>
</html>