Php: how to obtain keywords for accessing websites from Baidu, Google, and other search engines

Source: Internet
Author: User
This article mainly introduces how php can obtain keywords for accessing websites from Baidu, Google, and other search engines. It can be used to determine the source of the search engines that enter the website and search keywords. It is very simple and practical, for more information, see

This article mainly introduces how php can obtain keywords for accessing websites from Baidu, Google, and other search engines. It can be used to determine the source of the search engines that enter the website and search keywords. It is very simple and practical, for more information, see

This example describes how php can obtain keywords for accessing websites from search engines such as Baidu and Google. Share it with you for your reference. The specific implementation method is as follows:

<? Phpfunction 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 = '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' => $ keywor D, 'from' => $ from);} // test the keyword in the search engine. Enter the website $ word = search_word_from (); if (! Empty ($ word ['keyword']) {echo 'keyword :'. $ word ['keyword']. 'from :'. $ word ['from'];}?>

I hope this article will help you with php programming.

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.