Home >Backend Development >PHP Tutorial >Simple code example of php counter

Simple code example of php counter

WBOY
WBOYOriginal
2016-07-25 08:59:04880browse
  1. /*

  2. * Example 1, text file recording data
  3. * edit bbs.it-home.org
  4. */
  5. $counter=1;
  6. if(file_exists( "mycounter.txt")){
  7. $fp=fopen("mycounter.txt","r");
  8. $counter=fgets($fp,9);
  9. $counter++;
  10. fclose($fp);
  11. }
  12. $fp=fopen("mycounter.txt","w");
  13. fputs($fp,$counter);
  14. fclose($fp);
  15. echo "

    You are the ".$counter." Visits to this page!

  16. $result=mysql_query("use db_counter");
  17. $re=mysql_query("select * from tb_counter");
  18. $result=mysql_fetch_row($re);
  19. $counter=$result[0];
  20. echo "You Is the {$counter}th visitor! ";
  21. $counter+=1;echo "
    {$counter}";
  22. mysql_query("update tb_counter set counter=$counter");
  23. mysql_close($conn) ;
  24. //Just a simple counter, you can add the function to prevent repeated refresh
  25. ?>

Copy code
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