PHP gets the detailed code of keywords entering the website from Baidu search_PHP tutorial

WBOY
Release: 2016-07-13 10:41:35
Original
746 people have browsed it

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.

www.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()...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template