PHP text-based Graphics Display counter

Source: Internet
Author: User
Tags count

Create count.txt text file and index.php, prepare 1-9 altogether nine numbers of pictures, online can find this kind of picture, respectively named: 1-9
Count.txt file, save the number of visits, such as input 100
index.php:

 
 
  1. <?php
  2. Select a color to display statistics
  3. $color _name= "Black_white";
  4. $color _name= "White_black";
  5. $color _name= "Black_transparent";
  6. Open file read-only mode
  7. $FP =fopen ("Counter.txt", "R");
  8. Reading data
  9. $counter =fgets ($FP, 1024);
  10. Close File
  11. Fclose ($FP);
  12. Counter increased by 1
  13. $counter + +;
  14. Open files in writable mode
  15. $FP =fopen ("Counter.txt", "w");
  16. Write new statistics to a text file
  17. Fputs ($fp, $counter);
  18. Close File
  19. Fclose ($FP);
  20. To prevent other users from accessing the page at this time, the contents of the file have changed
  21. Reopen the file to read the latest statistics
  22. $FP =fopen ("Counter.txt", "R");
  23. $counter =fgets ($FP, 1024);
  24. Fclose ($FP);
  25. Loop to display statistical data in images
  26. Different numbers for different images
  27. If the number 1, then the image 1.gif to display
  28. for ($i =0; $i <strlen ($counter); $i + +)
  29. {
  30. $result = $counter [$i];
  31. Switch ($result)
  32. {
  33. Case "0": $ret [$i]= "0.gif";    Break Show a digital picture
  34. Case "1": $ret [$i]= "1.gif"; Break
  35. Case "2": $ret [$i]= "2.gif"; Break
  36. Case "3": $ret [$i]= "3.gif"; Break
  37. Case "4": $ret [$i]= "4.gif"; Break
  38. Case "5": $ret [$i]= "5.gif"; Break
  39. Case "6": $ret [$i]= "6.gif"; Break
  40. Case "7": $ret [$i]= "7.gif"; Break
  41. Case "8": $ret [$i]= "8.gif"; Break
  42. Case "9": $ret [$i]= "9.gif"; Break
  43. }
  44. }
  45. echo "The total number of visits to this page is:";
  46. Loop output Image
  47. for ($i =0; $i <sizeof ($ret); $i + +)
  48. echo "
  49. ?>






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.