php防止灌水

<?php
header("content-type:text/html;charset=utf-8");
//echo "<pre>";
//print_r($GLOBALS);
//echo "</pre>";
header("content-type:text/html;charset=utf-8");
if(!defined('interval')) define('interval', 10);//定义常量:时间间隔为5秒
if(!defined('now_time')) define('now_time', time());//定义常量:当前时间
$refresh_time = isset($_COOKIE['refresh_time']) ? intval($_COOKIE['refresh_time']) : 0;

if ($refresh_time == 0)
{
    echo "init";
    setcookie('refresh_time', now_time - interval);//第一次访问
}
elseif ($refresh_time > (now_time - interval))
{
    $temp = $refresh_time + interval - now_time;
    echo "防刷新机制,请过" . ($refresh_time + interval - now_time)."秒钟后重试。";
    exit();
}
else
{
    setcookie('refresh_time', now_time);//此时正常输出
    echo "ok";
}
?>

    A+
发布日期:2014年09月15日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: