Using PHP to record the search engine Routing and user search input keywords, the code is as follows:
<?php
function Recordurlkeywords ($url) {
$spider =array (' Baidu. ') => ' Baidu ', ' Google. ' => ' Google ', ' Soso. ' => ' search ', ' Sogou. ' => ' Sogou ', ' www.so.com ' => ' 360 ');
$q =array (' Baidu ' => '/wd= ([^&]*)/I ', ' Google ' => '/q= ' ([^&]*)/I ', ' 360 ' => ']/q= ' (. *)/I ', ' Sogou ' => '/query= ([^ &]*) I/I ', ' Search ' => '/w= ([^&]*)/I ');
Author:www. Alixixi.com
foreach ($spider as $k => $v) {
if (Strpos ($url, $k)) {
Preg_match ("{$q [$v]}", $url, $b);
if ($v = = ' search ' $v = = ' Sogou ') {
$keywords =iconv (' GBK ', ' UTF-8 ', UrlDecode ($b [1]));
} else{
$keywords =urldecode ($b [1]);
}
echo "keyword from {$v}:". $keywords;
}
}} $url =$_server[' http_referer '];//get the website source address
Recordurlkeywords ($url);