Home > Backend Development > PHP Tutorial > PHP code example for recording search engine keywords

PHP code example for recording search engine keywords

WBOY
Release: 2016-07-25 08:57:22
Original
1141 people have browsed it
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)



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template