zoukankan      html  css  js  c++  java
  • PHP获取搜索引擎关键字来源(百度、谷歌、雅虎、搜狗、搜搜、必应、有道)

    <?php
    //获取来自搜索引擎入站时的关键词
    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"; //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
     
     $google=preg_match("/{$search_1}/",$url);//记录匹配情况,用于入站判断。
     $baidu=preg_match("/{$search_2}/",$url);
     $yahoo=preg_match("/{$search_3}/",$url);
     $sogou=preg_match("/{$search_4}/",$url);
     $soso=preg_match("/{$search_5}/",$url);
     $bing=preg_match("/{$search_6}/",$url);
     $youdao=preg_match("/{$search_7}/",$url);
     $s_s_keyword="";
     $bul=$_SERVER['HTTP_REFERER'];
     //获取没参数域名
     preg_match('@^(?:http://)?([^/]+)@i',$bul,$matches);
     $burl=$matches[1];
     //匹配域名设置
     $curl="www.netxu.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($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;
       $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"];
     }
    ?>
  • 相关阅读:
    3、Ubantu下安装nginx
    2、关于mongodb外部访问不成功的问题
    1. libcurl.so.4: cannot open shared object file: No such file or directory
    Php 笔记
    Jade之Plain Text
    Jade之Mixins
    Jade之Interpolation
    Jade之Template Inheritance
    Jade之Includes
    Jade之Filters
  • 原文地址:https://www.cnblogs.com/wawahaha/p/3456842.html
Copyright © 2011-2022 走看看