The following are the relevant implementation codes:
Copy the Code code as follows:
/*
Plugin Name:display-search-keywords
Plugin uri:http://www.imyxiao.com/1531.html
Description: When a visitor comes to your blog via a search engine, this plugin can show the keywords of the visitor search
version:1.0
Author: Yang Xiao
*/
function Unescape ($STR) {
$ret = ";
$len = strlen ($STR);
for ($i = 0; $i < $len; $i + +) {
if ($str [$i] = = '% ' && $str [$i +1] = = ' U ') {
$val = Hexdec (substr ($str, $i +2, 4));
if ($val < 0x7f)
$ret. = Chr ($val);
Else
if ($val < 0x800)
$ret. = Chr (0xc0 | ($val >> 6)) . Chr (0x80 | ($val & 0x3f));
Else
$ret. = Chr (0xe0 | ($val >> 12)) . Chr (0x80 | (($val >> 6) & 0x3f)) . Chr (0x80 | ($val & 0x3f));
$i + = 5;
} else
if ($str [$i] = = '% ') {
$ret. = UrlDecode (substr ($str, $i, 3));
$i + = 2;
} else
$ret. = $st r[$i];
}
return $ret;
}
Function Ls_get_delim ($ref) {
$search _engines = Array (
' google.com.hk ' = ' Q ',
' google.com.tw ' = ') Q ',
' go.google.com ' + ' q ',
' google.com ' = ' Q ',
' blogsearch.google.com ' = ' Q ',
' cn.bing.com ' = > ' q ',
' one.cn.yahoo.com ' + ' P ',
' baidu.com ' + ' wd ',
' soso.com ' + ' W ',
' youdao.com ' = ' Q ',
' sogou.com ' = ' query '
),
$delim = false;
//Judgment
if (isset ($search _engines[$ref])) {
$delim = $search _engines[$ref];
}
return $delim;
}
function Ls_get_refer () {
Determine the URL address of the previous page
$queryString = $_get[' referer ');
$queryString = unescape ($queryString);
if (!isset ($queryString) | | ($queryString = = "))
return false;
$referer _info = Parse_url ($queryString);
$referer = $referer _info[' host '];
Remove www.
if (substr ($referer, 0, 4) = = ' www. ')
$referer = substr ($referer, 4);
return $referer;
}
function Ls_getinfo ($what) {
$referer = Ls_get_refer ();
if (! $referer)
return false;
$delimiter = Ls_get_delim ($referer);
if ($delimiter) {
$terms = Ls_get_terms ($delimiter);
if ($what = = ' Isref ' && $terms! = ') {
return true;
}
if ($what = = ' terms ') {
Echo $terms;
}
}
return false;
}
function Yxiao_seems_utf8 ($STR) {
$length = strlen ($STR);
for ($i = 0; $i < $length; $i + +) {
$c = Ord ($str [$i]);
if ($c < 0x80)
$n = 0; # 0BBBBBBB
ElseIf (($c & 0xE0) = = 0xC0) $n = 1; # 110BBBBB
ElseIf (($c & 0xF0) = = 0xE0) $n = 2; # 1110BBBB
ElseIf (($c & 0xF8) = = 0xF0) $n = 3; # 11110BBB
ElseIf (($c & 0xFC) = = 0xF8) $n = 4; # 111110BB
ElseIf (($c & 0xFE) = = 0xFC) $n = 5; # 1111110b
Else
return false; # Does not match any model
for ($j = 0; $j < $n; $j + +) {# n bytes matching 10bbbbbb follow?
if ((+ + $i = = $length) | | (Ord ($str [$i]) & 0xC0)! = 0x80))
return false;
}
}
return true;
}
function Ls_get_terms ($d) {
Get Query Value
$queryString = $_get[' referer ');
$queryString = unescape ($queryString);
$query _str = Parse_url ($queryString);
Parse_str ($query _str[query], $query _str);
$query = $query _str[$d];
$query = UrlDecode ($query);
$query = Str_replace ("'", "', $query);
$query = Str_replace (' "', ' ', $query);
$query _array = Preg_split ('/[\s,\+\.] +/', $query);
$query _terms = Implode (", $query _array);
$terms = Htmlspecialchars ($query _terms);
Gbk->utf8
if (!yxiao_seems_utf8 ($terms)) {
$terms = Iconv ("GBK", "Utf-8//ignore", $terms);
}
return $terms;
}
if (Ls_getinfo (' Isref ')) {
?>
document.write ('
')
document.write (' More search results: ')
document.write (' title= ' search results for "rel=" nofollow "> ")
document.write ('
');
http://www.bkjia.com/PHPjc/735237.html www.bkjia.com true http://www.bkjia.com/PHPjc/735237.html techarticle here is the relevant implementation code: Copy code code as follows: PHP/* Plugin name:display-search-keywords Plugin uri:http://www.imyxiao.com/1531.html DESCR Iption: When visitors search by ...