Copy CodeThe code is as follows:
/ * Simple implementation of recording data using a text file */
$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 first ". $counter." Times to visit this page!
";
?>
Copy CodeThe code is as follows:
//The following is a simple database-based counter that does not add other methods that prevent one person from repeating the refresh. For informational purposes 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 first {$counter} visitor! ";
$counter +=1;echo "{$counter}";
mysql_query ("Update tb_counter set counter= $counter");
Mysql_close ($conn);
?>
http://www.bkjia.com/PHPjc/327475.html www.bkjia.com true http://www.bkjia.com/PHPjc/327475.html techarticle Copy the code as follows: PHP/* Simple implementation of data logging using text files */$counter =1; if (file_exists ("Mycounter.txt") {$fp =fopen ("Mycounter.txt", "R") ; $counter =fgets ($fp, 9 ...