PHP visitor counter

巴扎黑
Release: 2016-11-23 11:20:37
Original
1795 people have browsed it

<?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;
}
?>
Copy after login

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";

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template