Home > php教程 > php手册 > PHP计数器的实现代码

PHP计数器的实现代码

WBOY
Release: 2016-06-06 20:31:23
Original
1094 people have browsed it

本篇文章是对PHP计数器的实现代码进行了详细的分析介绍,需要的朋友参考下

复制代码 代码如下:


/*使用文本文件记录数据的简单实现*/
$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 "

您是第".$counter."次访问本页面!

";
?>

复制代码 代码如下:


//下面这个为使用基于数据库的简单计数器,香港服务器租用,未添加其他防止一人重复刷新的方法。仅供参考。。
$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 "您是第{$counter}位访问者!";
$counter+=1;echo "


{$counter}";
mysql_query("update tb_counter set counter=$counter");
mysql_close($conn);
?>

,香港服务器租用,香港虚拟主机
Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template