1 <?php 2 3 function search_word_from() { 4 $referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:''; 5 if(strstr( $referer, 'baidu.com')){ //百度 6 preg_match( "|baidu.+wo?r?d=([^\&]*)|is", $referer, $tmp ); 7 $keyword = urldecode( $tmp[1] ); 8 $from = 'baidu'; (PS:T不错的PHP Q扣峮:276167802,验证:csl) 9 }elseif(strstr( $referer, 'google.com') or strstr( $referer, 'google.cn')){ //谷歌 10 preg_match( "|google.+q=([^\&]*)|is", $referer, $tmp ); 11 $keyword = urldecode( $tmp[1] ); 12 $from = 'google'; www.jbxue.com 13 }elseif(strstr( $referer, 'so.com')){ //360搜索 14 preg_match( "|so.+q=([^\&]*)|is", $referer, $tmp ); 15 $keyword = urldecode( $tmp[1] ); 16 $from = '360'; 17 }elseif(strstr( $referer, 'sogou.com')){ //搜狗 18 preg_match( "|sogou.com.+query=([^\&]*)|is", $referer, $tmp ); 19 $keyword = urldecode( $tmp[1] ); 20 $from = 'sogou'; 21 }elseif(strstr( $referer, 'soso.com')){ //搜搜 22 preg_match( "|soso.com.+w=([^\&]*)|is", $referer, $tmp ); 23 $keyword = urldecode( $tmp[1] ); 24 $from = 'soso'; 25 }else { 26 $keyword =''; 27 $from = ''; 28 } 29 30 return array('keyword'=>$keyword,'from'=>$from); 31 } 32 33 //以下为测试 34 //在搜索引擎搜索个关键词,进入网站 35 $word = search_word_from(); 36 if(!empty($word['keyword'])){ 37 echo '关键字:'.$word['keyword'].' 来自:'.$word['from']; 38 } 39 ?>