there!我寫了一段代碼來對抗我的網站vistor沒有刷新。以下是我的代碼,任何人都可以給我一些關於代碼的提示,並給出一些建議?php counter避免刷新
<?php
$counterFile='counter.txt';
$ipFile='ip.txt';
if(!is_file($counterFile)){
file_put_contents($counterFile,0);
}
if(!is_file($ipFile)){
file_put_contents($ipFile,0);
}
$handle=fopen($counterFile,'rb') or die('error:can not open the counter file');
$fileSize=filesize($counterFile);
$counter=intval(fread($handle,$fileSize));
fclose($handle);
/**----$counter=file_get_contents($counterFile);----***/
$oldIp=file_get_contents($ipFile);
$currIp=$_SERVER['REMOTE_ADDR'];
//echo $oldIp.'==='.$currIp;
if($oldIp!=$currIp){
++$counter;
$handle=fopen($counterFile,'wb');
fwrite($handle,$counter);
fclose($handle);
/**----file_put_contents($counterFile,$counter);----***/
}
file_put_contents($ipFile,$currIp);
echo $counter;
?>
OMFG。人們還在做櫃檯嗎? –
這個問題似乎是無關緊要的,因爲它涉及代碼審查,因此更適合http://codereview.stackexchange.com/。 – Carsten
爲什麼不使用Google Analytics等網絡統計信息? – Pitchinnate