thinkPHP下简单的网站访问量统计
程序员文章站
2024-01-29 14:25:34
...
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';
}
}
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
}
if(!empty($yesterdayc)){
echo '昨天访问量:',$yesterdayc,'';
}else{
echo '昨天访问量:0';
}
if(!empty($sun)){
echo '总访问量:',$sun,'';
}else{
echo '总访问量:0';
}
}
AD:真正免费,域名+虚机+企业邮箱=0元
上一篇: leetcode 链表总结python