Home > Backend Development > PHP Tutorial > PHP获取搜索引擎来路以及搜索关键字的方法

PHP获取搜索引擎来路以及搜索关键字的方法

WBOY
Release: 2016-06-20 13:04:04
Original
1395 people have browsed it

利用php记录搜索引擎的来路以及用户搜索输入的关键字,代码如下:

<p><?php</p>function recordUrlKeywords($url){<br /> $spider=array('baidu.'=>'百度','google.'=>'谷歌','soso.'=>'搜搜','sogou.'=>'搜狗','www.so.com'=>'360');<br /> $q=array('百度'=>'/wd=([^&]*)/i','谷歌'=>'/q=([^&]*)/i','360'=>'/q=(.*)/i','搜狗'=>'/query=([^&]*)/i','搜搜'=>'/w=([^&]*)/i');<br /> //author:www.phpernote.com<br /> foreach($spider as $k=>$v){<br /> if(strpos($url,$k)){<br /> preg_match("{$q[$v]}",$url,$b);<br /> if($v=='搜搜'||$v=='搜狗'){<br /> $keywords=iconv('GBK','UTF-8',urldecode($b[1]));<br /> }else{<br /> $keywords=urldecode($b[1]);<br /> }<br /> echo "来自{$v}的关键字:".$keywords;<br /> }<br /> }<br />}<br />$url=$_SERVER['HTTP_REFERER'];//获取网站来源地址<br />recordUrlKeywords($url);
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template