[PHP] 纯文本查看 复制代码
<?php
//功能代码
define('TIME_OUT', 120); //这里设置时间,单位为秒
@session_start();
$time = time();
if( isset($_SESSION['time']) )
{
if( $time - $_SESSION['time'] <= TIME_OUT ) //超时判断
{
echo '<script type=text/javascript>alert("超过限制时的提示文字!");</script>';
exit();
}
}
$_SESSION['time'] = $time;
echo "正常情况的显示";
//获取IP的PHP函数
function ClientIP()
{
$realip = "";
if (isset($_SERVER))
{
// 如果$_SERVER['HTTP_X_FORWARDED_FOR']有值表明客户端通过代理上网
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip_arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
/* 取X-Forwarded-For中第一个非unknown的有效IP字符串 */
foreach ($ip_arr as $ip)
{
$ip = trim($ip);
if ($ip != 'unknown')
{
$realip = $ip;
break;
}
}
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$realip = $_SERVER['HTTP_CLIENT_IP'];
} else {
if (isset($_SERVER['REMOTE_ADDR']))
$realip = $_SERVER['REMOTE_ADDR'];
else
$realip = '0.0.0.0';
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR')) // 如果getenv('HTTP_X_FORWARDED_FOR')非空取其值作为真实IP
$realip = getenv('HTTP_X_FORWARDED_FOR');
elseif (getenv('HTTP_CLIENT_IP')) // 如果getenv('HTTP_CLIENT_IP')非空取其值作为真实IP
$realip = getenv('HTTP_CLIENT_IP');
else
$realip = getenv('REMOTE_ADDR');
}
preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
$realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
return $realip;
}
?>