首页 > 后端开发 > php教程 > php»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê_PHP教程

php»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê_PHP教程

WBOY
发布: 2016-07-20 11:12:33
原创
4025 人浏览过

php»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê

<?php
 
function search_word_from() {
    $referer = isset($_SERVER[&#39;HTTP_REFERER&#39;])?$_SERVER[&#39;HTTP_REFERER&#39;]:&#39;&#39;;
    if(strstr( $referer, &#39;baidu.com&#39;)){ //°Ù¶È
        preg_match( "|baidu.+wo?r?d=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = &#39;baidu&#39;;
    }elseif(strstr( $referer, &#39;google.com&#39;) or strstr( $referer, &#39;google.cn&#39;)){ //¹È¸è
        preg_match( "|google.+q=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = &#39;google&#39;;
    }elseif(strstr( $referer, &#39;so.com&#39;)){ //360ËÑË÷
        preg_match( "|so.+q=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = &#39;360&#39;; 
    }elseif(strstr( $referer, &#39;sogou.com&#39;)){ //Ëѹ·
        preg_match( "|sogou.com.+query=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = &#39;sogou&#39;;   
    }elseif(strstr( $referer, &#39;soso.com&#39;)){ //ËÑËÑ
        preg_match( "|soso.com.+w=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = &#39;soso&#39;;
    }else {
        $keyword =&#39;&#39;;
        $from = &#39;&#39;;
    }
 
    return array(&#39;keyword&#39;=>$keyword,&#39;from&#39;=>$from);
}
 
//ÒÔÏÂΪ²âÊÔ
//ÔÚËÑË÷ÒýÇæËÑË÷¸ö¹Ø¼ü´Ê£¬½øÈëÍøÕ¾
$word = search_word_from();
if(!empty($word[&#39;keyword&#39;])){
    echo &#39;¹Ø¼ü×Ö£º&#39;.$word[&#39;keyword&#39;].&#39; À´×Ô£º&#39;.$word[&#39;from&#39;];
}
?>
登录后复制

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444549.htmlTechArticlephp»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê ?php function search_word_from() { $referer = isset($_SERVER[HTTP_REFERER])?$_SERVER[HTTP_REFERER]:; if(strstr( $refe...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板