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...