PHP counter implementation code

Source: Internet
Author: User
This article provides a detailed analysis of the PHP counter implementation code. For more information, see The code is as follows:
/* Simple implementation of recording data using text files */
$ Counter = 1;
If (file_exists ("mycounter.txt ")){
$ Fp = fopen ("mycounter.txt", "r ");
$ Counter = fgets ($ fp, 9 );
$ Counter ++;
Fclose ($ fp );
}
$ Fp = fopen ("mycounter.txt", "w ");
Fputs ($ fp, $ counter );
Fclose ($ fp );
Echo "you are the". $ counter. "times to access this page! ";
?>

The code is as follows:
// The following is a simple database-based Counter. No other methods are added to prevent refresh by one person. For reference only ..
$ Conn = mysql_connect ("localhost", "root", "abc ");
$ Result = mysql_query ("use db_counter ");
$ Re = mysql_query ("select * from tb_counter ");
$ Result = mysql_fetch_row ($ re );
$ Counter = $ result [0];
Echo "you are the {$ counter} visitor! ";
$ Counter + = 1; echo "{$ counter }";
Mysql_query ("update tb_counter set counter = $ counter ");
Mysql_close ($ conn );
?>

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.