Share a PHP code to get the keywords entered into the website from Baidu search. Friends in need can refer to it:
Code:
Copy the code The code is as follows:
function search_word_from() {
$referer = isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']: '';
if(strstr( $referer, 'baidu.com')){ //Baidu
preg_match( "|baidu.+wo?r?d=([^\&]*)|is ", $referer, $tmp );
$keyword = urldecode( $tmp[1] );
$from = 'baidu'; (PS: T good PHP Q buckle: 276167802, verification: csl )
}elseif(strstr( $referer, 'google.com') or strstr( $referer, 'google.cn')){ //Google
preg_match( "|google.+q=([^ \&]*)|is", $referer, $tmp );
$keyword = urldecode( $tmp[1] );
$from = 'google';
}elseif(strstr( $ referer, 'so.com')){ //360 Search
preg_match( "|so.+q=([^\&]*)|is", $referer, $tmp );
$keyword = urldecode( $tmp[1] );
$from = '360';
}elseif(strstr( $referer, 'sogou.com')){ //Sogou
preg_match( "|sogou .com.+query=([^\&]*)|is", $referer, $tmp );
$keyword = urldecode( $tmp[1] );
$from = 'sogou';
}elseif(strstr( $referer, 'soso.com')){ //Soso
preg_match( "|soso.com.+w=([^\&]*)|is", $ referer, $tmp );
$keyword = urldecode( $tmp[1] );
$from = 'soso';
}else {
$keyword ='';
$ from = '';
}
return array('keyword'=>$keyword,'from'=>$from);
}
//The following For testing
//Search for a keyword in the search engine, enter the website
$word = search_word_from();
if(!empty($word['keyword'])){
echo ' Keyword: '.$word['keyword'].' From: '.$word['from'];
}
?>
The above is the article about php How to get the detailed code of keywords entered into the website from Baidu search. I hope this article will be helpful to the majority of PHP developers. Thank you for reading this article.
http://www.bkjia.com/PHPjc/676887.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/676887.htmlTechArticleShare a PHP code to get the keywords entering the website from Baidu search. Friends in need can refer to it: Code : Copy the code as follows: ?php function search_word_from()...