时间:2021-07-01 10:21:17 帮助过:9人阅读
error_reporting(0);
session_start();
require_once 'config.php';
require_once COMMON_PATH.'Common.php';
$common = new Common();
date_default_timezone_set ('Asia/Shanghai');
$weil = strtotime("2013-08-07 23:59:59");
$now = time();
if($weil-$now < 0){//投票时间过期
echo 0;
exit;
}
$ip = $common->getClientIp();
$id = $_POST['id'];
$ipid=$ip.$id;
if($_SESSION['ipid']==$ipid||$_COOKIE['ipid']==$ipid){
//$array = array('48','49','67','47');
//if ( in_array($id,$array) ) {
echo 2;
} else {
$tbName = TB_NAME;
$limit_time = 3600;
$arr = $common->getItems('id,addTime','20130618_ztao_jtsjip','id','desc',"where tpId='$id' and ip='$ip'");
$row = false;
if (count($arr) > 0) {
$row = $arr[0];
}
if(!$row){
$common->insertItems('20130618_ztao_jtsjip','tpId,ip,addTime',"'$id','$ip','$now'");
$res = $common->updateItems("$tbName",'voteNum=voteNum+1',"$id");
$_SESSION['ipid']=$ipid;
setcookie("ipid","$ipid",time()+$limit_time);
if($res == true){
echo 1;//投票成功
}else{
echo 3;
}
}else if(($now-$row['addTime'])>$limit_time){
$common->insertItems('20130618_ztao_jtsjip','tpId,ip,addTime',"'$id','$ip','$now'");
$res = $common->updateItems("$tbName",'voteNum=voteNum+1',"$id");
$_SESSION['ipid']=$ipid;
setcookie("ipid","$ipid",time()+$limit_time);
if($res == true){
echo 1;
}else{
echo 3;
}
}else if(($now-$row['addTime'])<$limit_time){
echo 2;
}else{
echo 3;
}
}
?>
if($_SESSION['ipid']==$ipid
------解决方案--------------------
$_COOKIE['ipid']==$ipid)