class BaseAction extends Action {
public function _initialize() {
//访客来源判断
$refer = $_SERVER["HTTP_REFERER"];//获取上一页面地址
if($refer){
$refer_string = parse_url($refer, PHP_URL_HOST);//
$arr=array("baidu","soso","sogou","so","google","bing","yahoo","youdao");//常用搜索引擎,注意"soso","sogou","so"的顺序
foreach($arr as $re){
if(substr_count($refer_string,$re)>=1){
$map['type'] = $re;
break;
}
}
M("engines")->where($map)->setInc('counts',1);
}else{
$map['type'] = 'direct';
M("engines")->where($map)->setInc('counts',1);
}
}
在后台管理页面中插入以下代码,显示饼形图统计效果:public function main()
{
/*引入GoogChart类*/
import("ORG.Util.GoogChart");
$chart = new GoogChart();
$engine=M("engines")->field('type,name,counts')->select();
//设置$data数组数据;
foreach($engine as $k=>$value){
$data[$value[name].",".$value[counts]."次访问"]=$value[counts];
}
//设置颜色值
$color = array(
'#0181ec'
);
$chart->setChartAttrs( array(
'type' => 'pie',
'title' => '搜索引擎来源统计',
'data' => $data,
'size' => array( 550, 300 ),
'color' => $color
));
$this->assign('chart',$chart);
//设置$chart,通过页面模版中调用{$chart},显示统计图;
}
/**来源统计结束**/
附件,附上GoogChart.class.php类和example.php googchart_0_1.zip ( 3.12 KB 下载:135 次 )