Copy code The code is as follows:
/*Simple implementation of using text files to record data* /
$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 "
This is the ".$counter." time you visit this page!";
?>
Copy code The code is as follows:
//The following is a simple counter based on the database, and no other methods are added 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 {$counter}th visitor! ";
$ counter+=1;echo "
{$counter}";
mysql_query("update tb_counter set counter=$counter");
mysql_close($conn);
?>
http://www.bkjia.com/PHPjc/327475.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327475.htmlTechArticleCopy the code as follows: ?php /*Simple implementation of using text files to record data*/ $counter=1; if(file_exists("mycounter.txt")){ $fp=fopen("mycounter.txt","r"); $counter=fgets($fp,9...