//规则 if($_COOKIE['ip'] == $ip){ if(!empty($_COOKIE['zanid'])){ $zanidArr = explode(',', $_COOKIE['zanid']); if(in_array($id,$zanidArr)){ echo "<script>alert('该商品已经赞过,一小时内只允许赞一次!');history.go(-1);</script>"; die; }else{ array_unshift($zanidArr, $id); //入栈 } setcookie('zanid', implode(',', $zanidArr), time()+3600); } } else { setcookie('zanid', $id, time()+3600); setcookie("ip",$ip,time()+3600); }