This article introduces a piece of code that uses PHP to record search engine keywords. It is a good reference for beginners.
Use PHP to record search engine search keywords. The code is as follows: <?php /** * 记录搜索引擎搜索关键词 * edit by bbs.it-home.org */ //搜索来源 $rfr = $_SERVER['HTTP_REFERER']; //if(!$rfr) $rfr='http://'.$_SERVER['HTTP_HOST']; if($rfr) { $p=parse_url($rfr); parse_str($p['query'],$pa); $p['host']=strtolower($p['host']); $arr_sd_key=array( 'baidu.com'=>'word', 'google.com'=>'q', 'sina.com.cn'=>'word', 'sohu.com'=>'word', 'msn.com'=>'q', 'bing.com'=>'q', '163.com'=>'q', 'yahoo.com'=>'p' ); $keyword=''; $sengine=$p['host']; foreach($arr_sd_key as $se=>$kwd) { if(strpos($p['host'],$se)!==false) { $keyword=$pa[$kwd]; $sengine=$se; break; } } //写入搜索日志 $sql="insert into visit_log(domain,key_word,ct)"; } ?> Copy after login The code is very simple, mainly to give you an idea: By analyzing the source of the search engine, intercepting the relevant parameter values in the URL, then analyzing the keywords, matching the relevant searches, and recording them in the search log database. For more articles about recording search engine keywords, please refer to: php function to get search engine inbound keywords php implementation code for recording search engine origins and keywords php code to obtain the crawling records of each search spider php search and display keyword example php function to obtain search engine keyword sources (supports Baidu, Google and other search engines) |