PHP counter implementation code _ PHP Tutorial

Source: Internet
Author: User
PHP counter implementation code. Copy the code as follows :? Php * simple implementation of using text files to record data * counter1;if(file_exists(mycounter.txt?##fpfopen(mycounter.txt, r); $ counterfgets ($ fp, 9 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 );
?>


The http://www.bkjia.com/PHPjc/327475.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327475.htmlTechArticle code is as follows :? Php/* simple implementation of recording data using text files */$ counter = 1; if (file_exists ("mycounter.txt") {$ fp = fopen ("mycounter.txt ", "r"); $ counter = fgets ($ fp, 9...

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.