wl.php 1.97 KB
<?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>