1

1.代码示例

  $val['fromurl'] = $_SERVER['HTTP_REFERER'];

 if(!empty($val['fromurl']))
            {
                $str   = str_replace("https://","",$val['fromurl']);  //去掉http://
                $strdomain = explode("/",$str);               // 以“/”分开成数组
                $domain    = $strdomain[0];              //取第一个“/”以前的字符
                $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="so.com"; //w= gbk
                $search_6="bing.com"; //q= utf8
                $search_7="youdao.com"; //q= utf8

                $google=preg_match("/\b{$search_1}\b/",$domain);//来自谷歌
                $baidu=preg_match("/\b{$search_2}\b/",$domain);//来自百度
                $yahoo=preg_match("/\b{$search_3}\b/",$domain);//来自雅虎
                $sogou=preg_match("/\b{$search_4}\b/",$domain);//来自搜狗
                $soso=preg_match("/\b{$search_5}\b/",$domain);//来自搜搜
                $bing=preg_match("/\b{$search_6}\b/",$domain);//来自必应
                $youdao=preg_match("/\b{$search_7}\b/",$domain);//来自有道

                if($google)
                {
                    $this->_d['list'][$key]['fromName']= '谷歌';
                }
                if($baidu)
                {
                    $this->_d['list'][$key]['fromName']= '百度';
                    if(strpos($val['fromurl'], '?') !== false) {
                        $result =  explode('wd=',$val['fromurl']);
                        $result =  explode('&',$result[1]);
                        $this->_d['list'][$key]['keyword'] = $result[0];
                    }
                    else
                    {
                        $this->_d['list'][$key]['keyword'] = '';
                    }
                }
                if($yahoo)
                {
                    $this->_d['list'][$key]['fromName']= '雅虎';
                }
                if($sogou)
                {
                    $this->_d['list'][$key]['fromName']= '搜狗';
                    if(strpos($val['fromurl'], '?') !== false) {
                        $result =  explode('?',$val['fromurl']);
                        $result =  explode('&',$result[1]);
                        $result =  explode('=',$result[0]);
                        $this->_d['list'][$key]['keyword'] = $result[1];
                    }
                    else
                    {
                        $this->_d['list'][$key]['keyword'] = '';
                    }
                }
                if($soso)
                {
                    $this->_d['list'][$key]['fromName']= '360搜索';
                    if(strpos($val['fromurl'], '?') !== false) {
                        $result =  explode('?',$val['fromurl']);
                        $result =  explode('&q=',$result[1]);
                        $this->_d['list'][$key]['keyword'] = $result[1];
                    }
                    else
                    {
                        $this->_d['list'][$key]['keyword'] = '';
                    }
                }
                if($bing)
                {
                    $this->_d['list'][$key]['fromName']= '必应';
                }
                if($youdao)
                {
                    $this->_d['list'][$key]['fromName']= '有道';
                }
           }

mmy123456
376 声望17 粉丝

有项目请联系:15201970281(毛毛)


« 上一篇
sql 操作记录
下一篇 »
java 笔记