Home > php教程 > php手册 > thinkPHP下简单的网站访问量统计

thinkPHP下简单的网站访问量统计

WBOY
Release: 2016-06-07 11:36:47
Original
3425 people have browsed it

thinkPHP下的网页简单访问量统计
mysql代码

create table count(
ip int(10) primary key not null auto_increment,
nowdate varchar(255),
nowdatec varchar(255)

)



thinkPHP控制器代码


public function count(){
ini_set('date.timezone','Asia/Shanghai');
$date=date('Y-m-d');
$yesterday=date("Y-m-d",strtotime("-1 day"));
$yesterdayc=M('count')->getfieldbynowdate($yesterday,'nowdatec');
$row=M('count')->where('nowdate="'.$date.'"')->select();
$n=1;
$add=array(
'nowdatec'=>$n,
'nowdate'=>$date,
);


if(empty($row)){
M('count')->add($add);
}
$row1=M('count')->field('nowdatec')->where('nowdate="'.$date.'"')->select();


foreach($row1 as $cd){
$dd= $cd['nowdatec'];
}




echo '今天访问量:',$dd,'';

$dd+=1;
$now=array(
'nowdatec'=>$dd,

'nowdate'=>$date,
);
M('count')->where('nowdate="'.$date.'"')->save($now);
$rows=M('count')->field('nowdatec')->select();
$sun=0;
for ($i=0;$i $sun+=$rows[$i]['nowdatec'];
}

if(!empty($yesterdayc)){
echo '昨天访问量:',$yesterdayc,'';
}else{
echo '昨天访问量:0';
}

if(!empty($sun)){
echo '总访问量:',$sun,'';
}else{
echo '总访问量:0';
}


}

AD:真正免费,域名+虚机+企业邮箱=0元

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