Home > Backend Development > PHP Tutorial > Implementation code of PHP counter_PHP tutorial

Implementation code of PHP counter_PHP tutorial

WBOY
Release: 2016-07-21 15:08:35
Original
1135 people have browsed it

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);
?>

www.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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template