PHP获取搜索关键字问题
网上找了一段代码想实现获取搜索关健字,测试了一个关健字取不了,是不是这代码无效了,还是那里有BUG?
//取搜索来源关健字
function get_keyword($url,$kw_start)
{
$start=stripos($url,$kw_start);
$url=substr($url,$start+strlen($kw_start));
$start=stripos($url,'&');
if ($start>0)
{
$start=stripos($url,'&');
$s_s_keyword=substr($url,0,$start);
}
else
{
$s_s_keyword=substr($url,0);
}
return $s_s_keyword;
}
$url=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'';//获取入站url。
$search_1="google.com.hk"; //q= utf8
$search_2="baidu.com"; //wd= gbk
$search_3="yahoo.cn"; //q= utf8
$search_4="sogou.com"; //query= gbk
$search_5="soso.com"; //w= gbk
$search_6="bing.com"; //q= utf8
$search_7="youdao.com"; //q= utf8
$search_8="so.com"; //q= utf8
$google=preg_match("/b{$search_1}b/",$url);//记录匹配情况,用于入站判断。
$baidu=preg_match("/b{$search_2}b/",$url);
$yahoo=preg_match("/b{$search_3}b/",$url);
$sogou=preg_match("/b{$search_4}b/",$url);
$soso=preg_match("/b{$search_5}b/",$url);
$bing=preg_match("/b{$search_6}b/",$url);
$youdao=preg_match("/b{$search_7}b/",$url);
$so=preg_match("/b{$search_8}b/",$url);
$s_s_keyword="";
// $bul=$_SERVER['HTTP_REFERER'];
$bul=$_REQUEST["comelink"];
//获取没参数域名
preg_match('@^(?:http://)?([^/]+)@i',$bul,$matches);
$burl=$matches[1];
//匹配域名设置
$curl="www.hcyf07.com";
if($burl!=$curl){
if ($google)
{//来自google
$s_s_keyword=get_keyword($url,'q=');//关键词前的字符为"q="。
$s_s_keyword=urldecode($s_s_keyword);
$urlname="谷歌:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
//$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
}
else if($baidu)
{//来自百度
$s_s_keyword=get_keyword($url,'wd=');//关键词前的字符为"wd="。
$s_s_keyword=urldecode($s_s_keyword);
$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="百度:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else if($yahoo)
{//来自雅虎
$s_s_keyword=get_keyword($url,'q=');//关键词前的字符为"q="。
$s_s_keyword=urldecode($s_s_keyword);
//$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="雅虎:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else if($sogou)
{//来自搜狗
$s_s_keyword=get_keyword($url,'query=');//关键词前的字符为"query="。
$s_s_keyword=urldecode($s_s_keyword);
$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="搜狗:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else if($soso)
{//来自搜搜
$s_s_keyword=get_keyword($url,'w=');//关键词前的字符为"w="。
$s_s_keyword=urldecode($s_s_keyword);
$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="搜搜:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else if($bing)
{//来自必应
$s_s_keyword=get_keyword($url,'q=');//关键词前的字符为"q="。
$s_s_keyword=urldecode($s_s_keyword);
//$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="必应:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else if($so)
{//来自360
$s_s_keyword=get_keyword($url,'q=');//关键词前的字符为"q="。
$s_s_keyword=urldecode($s_s_keyword);
//$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="360:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else if($youdao)
{//来自有道
$s_s_keyword=get_keyword($url,'q=');//关键词前的字符为"q="。
$s_s_keyword=urldecode($s_s_keyword);
//$s_s_keyword=iconv("GBK","UTF-8",$s_s_keyword);//引擎为gbk
$urlname="有道:";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
else{
// $urlname=$burl;
$urlname="直接访问";
$s_s_keyword="";
$_SESSION["urlname"]=$urlname;
$_SESSION["s_s_keyword"]=$s_s_keyword;
}
$s_urlname=$urlname;
$s_urlkey=$s_s_keyword;
}
else{
$s_urlname=$_SESSION["urlname"];
$s_urlkey=$_SESSION["s_s_keyword"];
}
------解决方案--------------------
有什么错误提示吗?
------解决方案--------------------
你那么代码是N多年前的。
$_SERVER['HTTP_REFERER'] 不能获取 https:// 的网站。
现在为了安全考虑,几乎所有的搜索引擎都使用 https:// 而不是 http:// 。