PHP计数器的实现代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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 "<h1>您是第".$counter."次访问本页面!<h1>";
?>

复制代码 代码如下:

<?php
//下面这个为使用基于数据库的简单计数器,未添加其他防止一人重复刷新的方法。仅供参考。。
$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 "<hr>{$counter}";
mysql_query("update tb_counter set counter=$counter");
mysql_close($conn);
?>

相关文章

php中strtotime函数用法详解

本文实例讲述了php中strtotime函数用法。分享给大家供大家参考。具体如下: strtotime(字符串$时间[,诠释$现在])int strtotime(string $time...

PHP中用hash实现的数组

PHP中使用最多的非Array莫属了,那Array是如何实现的?在PHP内部Array通过一个hashtable来实现,其中使用链接法解决hash冲突的问题,这样最坏情况下,查找Arra...

非常实用的php验证码类

本文实例为大家分享了php验证码类,供大家参考,具体内容如下 <?php /** * * @author Administrator * */ cl...

PHP使用函数用法详解

1.php_check_syntax 这个函数可以用来检查特定文件中的PHP语法是否正确。 <?php $error_message = ""; $filename =...

MongoDB在PHP中的常用操作小结

$mongodb = new Mongo(); //$connection = new Mongo( "$dburl:$port" ); // connect to a remote h...