Visits counter without database with PHP

前端 未结 5 643
花落未央
花落未央 2020-12-05 08:49

I have a single webpage and i would like to track how many times it\'s visited without using a database.

I thought about XML, updating a file every time a user visit

5条回答
  •  感情败类
    2020-12-05 09:24

     
       */ 
    
      // Open the file for reading 
      $fp = fopen("counterlog.txt", "r"); 
    
      // Get the existing count 
      $count = fread($fp, 1024); 
    
      // Close the file 
      fclose($fp); 
    
      // Add 1 to the existing count 
      $count = $count + 1; 
    
      // Display the number of hits 
      // If you don't want to display it, comment out this line    
      echo "

    Page views:" . $count . "

    "; // Reopen the file and erase the contents $fp = fopen("counterlog.txt", "w"); fwrite($fp, $count); // Close the file fclose($fp); ?>

提交回复
热议问题