PHP implementation of Web site visitor statistics method (simple implementation, not anti-refresh)

Source: Internet
Author: User

method One:<?PHPfunctionCounter ()//Defining Functions  {                                       $five= "00000";//declare variables, $five, $four and other variables to represent the number of zeros, placed in front of the number to constitute 6 digits    $four= "0000"; $three= "000"; $two= "00"; $one= "0"; $counter= "Rec.txt";//destination file for the number of accesses,. dat format    if(!file_exists($counter))//determine if a file exists    {      $counter=fopen($counter, "W"); $num= 1; fputs($counter, "1");//Write File      fclose($counter); Print"$five"."$num"; }Else{      $fp=fopen($counter, "r+"); $num=fgets($fp, "1024");//If the file exists, read the file and add 1      $num=$num+ 1; if($num< 10)        Print"$five"."$num"; ElseIf($num< 100)        Print"$four"."$num"; ElseIf($num< 1000)        Print"$three"."$num"; ElseIf($num< 10000)        Print"$two"."$num"; ElseIf($num< 100000)        Print"$one"."$num"; Else        Print"$num"; }    $fp=fopen("$counter"," W "); fputs($fp,"$num"); fclose($fp); }?>Method Two:PHP$counter=1; if(file_exists("Rec.txt"))        {          $fp=fopen("Rec.txt", "R"); $counter=fgets($fp, 1024); $counter++; fclose($fp); }        $fp=fopen("Rec.txt", "W"); fputs($fp,$counter); fclose($fp); Echo"<font size= ' 9 ' face= ' Verdana ' color= ' #FF0000 ' >".$counter." </font> "; ?> </B> <font size= "6" face= "Official script" > Visitors! </font> </center> </body>

PHP implementation of Web site visitor statistics method (simple implementation, not anti-refresh)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.