使用session我现在用的
session_start();
if(!isset($_SESSION['counter']))  {  
   $_SESSION['counter']  =  1;  
 
  $file  =    "counter.txt  ";  
//File  name  
 
//That's  it  
 
if(!file_exists("$file")){  
touch("$file");  
chmod("$file",0777);  
$fp=fopen("$file","r+");  
fseek($fp,0);  
$compteur  =  0;  
fputs($fp,$compteur);  
}  
 
if(  is_readable("$file")  and  is_writable("$file")){  
 
$fp=fopen("$file","r+");  
$compteur=fgets($fp,9999);  
fseek($fp,0);  
$compteur++;  
fputs($fp,$compteur);  
fclose($fp);  
print  $compteur;  
}  else  {  
chmod("$file",0777);  
}

解决方案 »

  1.   

    如果放在数据库记下ip,ip相同的或时间小N不记录
    这样就算关掉浏览器也不会再记多了
      

  2.   

    我是写DB的
    记IP和时间
    相同IP在1分钟内有重复的不算
      

  3.   

    如果你要求精确的话就用DB来记录IP和时间了!这个比较耗资源。如果只是简单的防范一下这种反复刷的人最好还是用session或者cookie好了。