This article describes the PHP to obtain from Baidu, Google and other search engines to enter the Site keyword methods. Share to everyone for your reference. The implementation method 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 '; }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);
//below for testing//search keywords in search engines, enter the site $word = Search_word_from ();
if (!empty ($word [' keyword ']) {echo ' keyword: '. $word [' keyword ']. ' From: '. $word [' from '];?>
I hope this article will help you with your PHP programming.