有人知道没有使用 CMS(Joomla、Drupal)但使用简单的 HTML、CSS、JS、PHP 构建的网站的访客计数器吗?最好有一个像 Vinaora 的 joomla 访客柜台那样的柜台,可以使用 here
谢谢。
最佳答案
不知道有哪个不依赖数据库来存储信息并将其精美地呈现给访问者。
依赖文本文件的解决方案可以像这样执行:
<?php
// file name and file path
$fileName = 'counter.txt';
$filePath = dirname(__FILE__).'/'.$fileName;
/*
* If the file exists
*/
if (is_file($filePath)) {
$fp = fopen($filePath, "c+"); // open the file for read/write
$data = fread($fp, filesize($filePath)); // ready entire file to variable
$arr = explode("\t", $data); // create array
// run by each array entry to manipulate the data
$c=0;
foreach($arr as $visit) {
$c++;
}
// output the result
echo '<div id="visits">'.$c.'</div>';
// write the new entry to the file
fwrite($fp,time()."\t");
// close the file
fclose($fp);
/*
* File does not exist
*/
} else {
$fp = fopen($filePath, "w"); // open the file to write
fwrite($fp, time()."\t"); // write the file
// output the data
echo '<div id="visits">1</div>';
// close the file
fclose($fp);
}
?>
此解决方案存储 PHP time()使用 PHP fwrite() 用 \t
分隔每次访问的次数, fread() , fopen()和 fclose() 。
利用存储的时间,您可以执行一些计算并显示包含您需要的详细信息的访问板。
上面的示例说明了所有这些,但仅显示了总访问量。
关于html - Vinaora 等简单网站的访客柜台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11138020/