Home php教程 PHP源码 PHP记录搜索引擎来路关键字

PHP记录搜索引擎来路关键字

May 25, 2016 pm 05:04 PM


<?php
/**
* 记录搜索引擎来路及关键词
* edit by www.jbxue.com
*/
//搜索引擎来路
function keywords($url){
$spier=array(&#39;baidu.&#39;=>&#39;百度&#39;,&#39;google.&#39;=>&#39;谷歌&#39;,&#39;soso.&#39;=>&#39;搜搜&#39;,&#39;sogou.&#39;=>&#39;搜狗&#39;,&#39;www.so.com&#39;=>&#39;360&#39;);
$q=array(&#39;百度&#39;=>&#39;/wd=([^&]*)/i&#39;,&#39;谷歌&#39;=>&#39;/q=([^&]*)/i&#39;,&#39;360&#39;=>&#39;/q=(.*)/i&#39;,&#39;搜狗&#39;=>&#39;/query=([^&]*)/i&#39;,&#39;搜搜&#39;=>&#39;/w=([^&]*)/i&#39;);
foreach($spier as $k=>$v){
   if(strpos($url,$k)){
      preg_match("{$q[$v]}",$url,$b);
      if($v==&#39;搜搜&#39;||$v==&#39;搜狗&#39;){
 $keywords=iconv(&#39;GBK&#39;,&#39;UTF-8&#39;,urldecode($b[1]));
      }else{
 $keywords=urldecode($b[1]);
}

echo "来自{$v}的关键字:".$keywords;
 }
} 
}
$url=$_SERVER[&#39;HTTP_REFERER&#39;]; //这个放到网站的头部来获取来访的地址的
      
keywords($url);

//记录用户搜索引擎关键词代码
//记录用户通过常见的搜索引擎搜索关键词
$rfr = $_SERVER[&#39;HTTP_REFERER&#39;];
//if(!$rfr) $rfr=&#39;http://&#39;.$_SERVER[&#39;HTTP_HOST&#39;];
if($rfr)
{
 $p=parse_url($rfr);
 parse_str($p[&#39;query&#39;],$pa);
 $p[&#39;host&#39;]=strtolower($p[&#39;host&#39;]);
 $arr_sd_key=array(
 &#39;baidu.com&#39;=>&#39;word&#39;,
 &#39;google.com&#39;=>&#39;q&#39;,
 &#39;sina.com.cn&#39;=>&#39;word&#39;,
 &#39;sohu.com&#39;=>&#39;word&#39;,
 &#39;msn.com&#39;=>&#39;q&#39;,
 &#39;bing.com&#39;=>&#39;q&#39;,
 &#39;163.com&#39;=>&#39;q&#39;,
 &#39;yahoo.com&#39;=>&#39;p&#39;
 );
 $keyword=&#39;&#39;;
 $sengine=$p[&#39;host&#39;];
 foreach($arr_sd_key as $se=>$kwd)
 {
if(strpos($p[&#39;host&#39;],$se)!==false)
{
 $keyword=$pa[$kwd];
 $sengine=$se;
 break;
}
 }
 $sql="insert into visit_log(domain,key_word,ct)";
}
?>
Copy after login

                   

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)