Share a php code for getting keywords from Baidu search to enter the website. For more information, see:
Code:
Copy codeThe Code is as follows:
<? Php
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 = '000000 ';
} 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') {// search
Preg_match ("| soso.com. + w = ([^ \ &] *) | is", $ referer, $ tmp );
$ Keyword = urldecode ($ tmp [1]);
$ From = 'soso ';
} Else {
$ Keyword = '';
$ From = '';
}
Return array ('keyword' => $ keyword, 'from' => $ from );
}
// The test is as follows:
// Search for keywords in the search engine and enter the website
$ Word = search_word_from ();
If (! Empty ($ word ['keyword']) {
Echo 'keyword: '. $ word ['keyword'].' from: '. $ word ['from'];
}
?>
The above is the detailed code of this article on how to obtain keywords for accessing websites from Baidu search. I hope this article will be helpful to php developers. Thank you for reading this article.