使用php记录用户通过搜索引擎进网站的关键词_php实例
时间:2021-07-01 10:21:17
帮助过:3人阅读
代码如下:
$rfr = $_SERVER['HTTP_REFERER'];
//if(!$rfr) $rfr='http://'.$_SERVER['HTTP_HOST'];
if($rfr)
{
$p=parse_url($rfr);
parse_str($p['query'],$pa);
$p['host']=strtolower($p['host']);
$arr_sd_key=array(
'baidu.com'=>'word',
'google.com'=>'q',
'sina.com.cn'=>'word',
'sohu.com'=>'word',
'msn.com'=>'q',
'bing.com'=>'q',
'163.com'=>'q',
'yahoo.com'=>'p'
);
$keyword='';
$sengine=$p['host'];
foreach($arr_sd_key as $se=>$kwd)
{
if(strpos($p['host'],$se)!==false)
{
$keyword=$pa[$kwd];
$sengine=$se;
break;
}
}
$sql="insert into visit_log(domain,key_word,ct)";
}