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.