Copy codeThe 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 );
$ Counter ++;
Fclose ($ fp );
}
$ Fp = fopen ("mycounter.txt", "w ");
Fputs ($ fp, $ counter );
Fclose ($ fp );
Echo "?>
Copy codeThe Code is as follows:
<? Php
// 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 "Mysql_query ("update tb_counter set counter = $ counter ");
Mysql_close ($ conn );
?>