2

CMS (Joomla、Drupal) を使用せずに単純な HTML、CSS、JS、PHP を使用して構築された Web サイトの訪問者カウンターを知っている人はいますか? ここで利用できる joomla の Vinaora ビジター カウンターのようなカウンターがあるとよいでしょう。

ありがとうございました。

4

1 に答える 1

2

情報を保存し、訪問者に美しく提示するためにデータベースに依存していないものは知りません。

テキスト ファイルに依存するソリューションは、次のように実行できます。

<?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 fwrite()fread()fopen()、およびfclose()を使用して区切られた各訪問の PHP time()を保存します。保存された時間を使用して、いくつかの計算を実行し、必要な詳細を含む訪問ボードを提示できます。\t

上記の例はこれらすべてを示していますが、訪問数の合計のみを示しています。

于 2012-06-21T13:39:59.250 に答える