两种方式:
第一:使用一个文本文档
每次读取这个文本文档的数,然后加1,再覆盖写入
关键代码:
$txt_db = 'jsb.txt';
$nums = file_get_contents($txt_db);
$nums++;
file_put_contents($txt_db,$nums);
?>
第二:使用数据库,设计数据表,每次更新数据库。
个人建议:使用第一种方法。
原因:需求简单,所以尽可能少占资源,抗压力强。
访问一面制作
Insert title here
php统计静态html页面浏览访问次数代码
统计数据库设计
--
-- 表的结构 `count`
--
CREATE TABLE IF NOT EXISTS `count` (
`id` int(11) NOT NULL auto_increment,
`aid` int(11) default NULL,
`click_num` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk AUTO_INCREMENT=2 ;
php处理页面代码
$aid = isset( $_GET['aid'] )?$_GET['aid']:'';
$t = isset( $_GET['t'] )?$_GET['t']:'';
if(intval( $aid )){
if( $t =='show' ){
echo "document.write('这里是显示浏览次数,可以从数据库读出来');";
}
else{
$conn = mysql_connect('localhost','root','root') ;
$sql = "Update count set click_num = click_num+1 where aid ='$aid'";
mysql_db_query('db_test',$sql,$conn);
}
}
?>
访问页面的时候数据库统计字段加1
session cookies