使用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);
}
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);
}
这样就算关掉浏览器也不会再记多了
记IP和时间
相同IP在1分钟内有重复的不算