113 lines
4.2 KiB
PHP
113 lines
4.2 KiB
PHP
<?php
|
||
namespace Home\Model;
|
||
class Tongji{
|
||
private $search_engine_inc=array(
|
||
"baidu." =>"baidu",
|
||
"google." =>"google",
|
||
"sogou." =>"sogou",
|
||
"so." =>"360",
|
||
"bing." =>"bing",
|
||
);
|
||
public function start(){
|
||
$visit_userId =$_COOKIE["visit_userId"];
|
||
if(!$visit_userId){
|
||
$data=array();
|
||
//进站方式
|
||
$http_referer=$_SERVER['HTTP_REFERER'];
|
||
if(!$http_referer){
|
||
$data['visit_type']="website";
|
||
}else{
|
||
$searcn_engine=$this->search_engine();
|
||
if($searcn_engine){
|
||
$data['visit_type']="search";
|
||
$data['search_engine']=$searcn_engine;
|
||
}else{
|
||
$data['visit_type']="link";
|
||
}
|
||
}
|
||
//ip地址
|
||
$data['ip']= get_client_ip(0,true);
|
||
//访问时间
|
||
$data['visit_time']=time();
|
||
//先插入48小时的表
|
||
M("visit_48")->add($data);
|
||
//再插入visit表
|
||
$today_start=strtotime(date("Y-m-d ")."00:00:00");
|
||
$today_end=strtotime(date("Y-m-d ")."23:59:59");
|
||
$where=array();
|
||
$where["visit_time"]=array("between",array($today_start,$today_end));
|
||
$data2=array();
|
||
//时间
|
||
$data2['daytime']=strtotime(date("Y-m-d"));
|
||
//IP统计
|
||
$ip_total=M("visit_48")->field("ip")->where($where)->group("ip")->select();
|
||
$data2['ip']=count($ip_total);
|
||
//pv统计
|
||
$data2['pv']=M("visit_48")->where($where)->count();
|
||
//visit_search 搜索进来的用户
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="search";
|
||
$data2['visit_search']=M("visit_48")->where($where2)->count();
|
||
//website 输入网址进来的用户
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="website";
|
||
$data2['visit_website']=M("visit_48")->where($where2)->count();
|
||
//link 通过链接跳转进来的用户
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="link";
|
||
$data2['visit_link']=M("visit_48")->where($where2)->count();
|
||
//各大搜索引擎判断
|
||
//baidu
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="search";
|
||
$where2["search_engine"]="baidu";
|
||
$data2['engine_baidu']=M("visit_48")->where($where2)->count();
|
||
//google
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="search";
|
||
$where2["search_engine"]="google";
|
||
$data2['engine_google']=M("visit_48")->where($where2)->count();
|
||
//sogou
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="search";
|
||
$where2["search_engine"]="sogou";
|
||
$data2['engine_sogou']=M("visit_48")->where($where2)->count();
|
||
//360
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="search";
|
||
$where2["search_engine"]="360";
|
||
$data2['engine_360']=M("visit_48")->where($where2)->count();
|
||
//bing
|
||
$where2=array();
|
||
$where2=$where;
|
||
$where2["visit_type"]="search";
|
||
$where2["search_engine"]="bing";
|
||
$data2['engine_bing']=M("visit_48")->where($where2)->count();
|
||
//
|
||
$visit_id=M("visit")->where(array("daytime"=>$data2['daytime']))->getField("id");
|
||
if($visit_id){
|
||
$data2["id"]=$visit_id;
|
||
M("visit")->save($data2);
|
||
}else{
|
||
M("visit")->add($data2);
|
||
}
|
||
//设置访问cookie,过期时间为今天23:59:59
|
||
setcookie("visit_userId",time()+rand(10000,99999), strtotime(date("Y-d-m")." 23:59:59"));
|
||
}
|
||
}
|
||
//判断搜索引擎
|
||
private function search_engine(){
|
||
foreach($this->search_engine_inc as $key=>$engine){
|
||
if(strstr($_SERVER['HTTP_REFERER'],$key)){
|
||
return $engine;
|
||
}
|
||
}
|
||
}
|
||
} |