Home  >  Article  >  Backend Development  >  PHP visitor counter

PHP visitor counter

巴扎黑
巴扎黑Original
2016-11-23 11:20:371785browse

<?php
//               PHP访客计数器
function num()
{
 if(!file_exists("n.txt"))
 {
  $fp=fopen("n.txt","w");
  fwrite($fp,"1");
  fclose($fp);
  $n=1;
 }
 else
 {
  $fp=fopen("n.txt","r");
  $n=fgets($fp);
  fclose($fp);
  $n++;
  $fp=fopen("n.txt","w");
  fwrite($fp,$n);
  fclose($fp);
 }
 return $n;
}
?>

When using this program, you need to upload it to the corresponding directory, and then add the following code to the page that displays the number of visitors:
require_once"count.php";
$guestsnum=num();
echo"You are the ".$guestsnum. "Visitor";

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn