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

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

WBOY
WBOY原创
2016-07-20 11:12:334032浏览

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...
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn