PHP to get the keyword from Baidu search into the site of the detailed code _php tips

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.