Copy Code code as follows:
<?php
/* 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 "?>
Copy Code code as follows:
<?php
The following is a simple database based counter that does not add other methods to prevent one person from repeatedly refreshing. 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 first {$counter} visitor!" ";
$counter +=1;echo "
mysql_query ("Update tb_counter set counter= $counter");
Mysql_close ($conn);
?>