Share a PHP access to the site from Baidu search keywords code, have the need for friends can refer to:
Code:
Copy Code code 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, Validation: 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 ')) {//Search
Preg_match ("|soso.com.+w= ([^\\&]*) |is", $referer, $tmp);
$keyword = UrlDecode ($tmp [1]);
$from = ' Soso ';
}else {
$keyword = ';
$from = ';
}
return array (' keyword ' => $keyword, the ' from ' => $from);
}
Here is the test
Search for a keyword in search engines, enter the site
$word = Search_word_from ();
if (!empty ($word [' keyword '])) {
echo ' keyword: '. $word [' keyword ']. ' From: '. $word [' from '];
}
?>
The above is this article on how to get the PHP search from Baidu to enter the site's keyword detailed code, I hope this article on the vast number of PHP developers help, thank you for reading this article.