欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2022-06-01 20:13:11
...
php»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê
<?php
 
function search_word_from() {
    $referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:^^ `;
    if(strstr( $referer, 'baidu.com')){ //°Ù¶È
        preg_match( "|baidu.+wo?r?d=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = 'baidu';
    }elseif(strstr( $referer, 'google.com') or strstr( $referer, 'google.cn')){ //¹È¸è
        preg_match( "|google.+q=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = 'google';
    }elseif(strstr( $referer, 'so.com')){ //360ËÑË÷
        preg_match( "|so.+q=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = '360'; 
    }elseif(strstr( $referer, 'sogou.com')){ //Ëѹ·
        preg_match( "|sogou.com.+query=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = 'sogou';   
    }elseif(strstr( $referer, 'soso.com')){ //ËÑËÑ
        preg_match( "|soso.com.+w=([^\\&]*)|is", $referer, $tmp );
        $keyword = urldecode( $tmp[1] );
        $from = 'soso';
    }else {
        $keyword =^^ `;
        $from = ^^ `;
    }
 
    return array('keyword'=>$keyword,'from'=>$from);
}
 
//ÒÔÏÂΪ²âÊÔ
//ÔÚËÑË÷ÒýÇæËÑË÷¸ö¹Ø¼ü´Ê£¬½øÈëÍøÕ¾
$word = search_word_from();
if(!empty($word['keyword'])){
    echo '¹Ø¼ü×Ö£º'.$word['keyword'].' À´×Ô£º'.$word['from'];
}
?>

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

相关标签: php