通常,如何在 JavaScript 中实现PHP 样式的Hit Counter ?
这个 PHP示例:
<?php
/* counter */
//opens countlog.txt to read the number of hits
$datei = fopen("/countlog.txt","r");
$count = fgets($datei,1000);
fclose($datei);
$count=$count + 1 ;
echo "$count" ;
echo " hits" ;
echo "\n" ;
// opens countlog.txt to change new hit number
$datei = fopen("/countlog.txt","w");
fwrite($datei, $count);
fclose($datei);
?>
在服务器上运行,而不是像 JavaScript 通常那样在浏览器中运行。