<?php<BR><STRONG>/*使用文本文件记录数据的简单实现*/<BR></STRONG>$counter=1;<BR>if(file_exists("mycounter.txt")){<BR>$fp=fopen("mycounter.txt","r");<BR>$counter=fgets($fp,9);<BR>$counter++;<BR>fclose($fp);<BR>}<BR>$fp=fopen("mycounter.txt","w");<BR>fputs($fp,$counter);<BR>fc<em style="color:transparent">本文来源gao.dai.ma.com搞@代*码#网</em><a>搞代gaodaima码</a>lose($fp);<BR>echo "<h1>您是第".$counter."次访问本页面!<h1>";<BR>?><BR>
<?php<BR><STRONG>//下面这个为使用基于数据库的简单计数器,未添加其他防止一人重复刷新的方法。仅供参考。。<BR></STRONG>$conn=mysql_connect("localhost","root","abc");<BR>$result=mysql_query("use db_counter");<BR>$re=mysql_query("select * from tb_counter");<BR>$result=mysql_fetch_row($re);<BR>$counter=$result[0];<BR>echo "您是第{$counter}位访问者!";<BR>$counter+=1;echo "<hr>{$counter}";<BR>mysql_query("update tb_counter set counter=$counter");<BR>mysql_close($conn);<BR>?><BR>