Php: get the detailed code for entering keywords from Baidu search website _ PHP

Source: Internet
Author: User
The following is a detailed code about how php can obtain keywords from Baidu search to enter the website. I hope this article will help a majority of php developers to share a php code for getting keywords from Baidu search to enter the website, if you have any need, refer:

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 = '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.

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.