而这样的话,又不能实现防刷新的功能?虽然有人说过可以的,但是事实上不可以。
<?php
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);
}
}
? >
<?php
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. 用session
2. 用cookie
3. 用自己设定的session id写进数据库来判断, 通过时间来控制
跟做在线统计差不多