Maison > Article > développement back-end > php»ñÈ¡´Ó°Ù¶ÈËÑË÷½øÈëÍøÕ¾µÄ¹Ø¼ü´Ê_PHP教程
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']; } ?>