html - Vinaora 等简单网站的访客柜台

标签 html hitcounter

有人知道没有使用 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/

相关文章:

jquery - 弹出窗口中的内容不显示在 IE 9 中

java - 使用 html 表单隐藏值将大文本发送到服务器

javascript - 一组间隔后生成数字

mysql - 博客页面点击计数器

java - 线程对方法的请求计数器

javascript - Bootstrap 将元素一个接一个地放置

javascript - 如何在没有 JavaScript 的情况下使元素相对于窗口具有粘性(如果可能)?

javascript示例显示内容框

python - Arduino 计数器