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

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

PHP中文网
Release: 2016-06-13 11:28:45
Original
1668 people have browsed it

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

<?php
 
function search_word_from() {
    $referer = isset($_SERVER[&#39;HTTP_REFERER&#39;])?$_SERVER[&#39;HTTP_REFERER&#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 =^^ `;
        $from = ^^ `;
    }
 
    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;];
}
?>
Copy after login

以上就是php»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Related labels:
php
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
Latest Articles by Author
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template