以下是相关实现代码:
复制代码 代码如下:
<?php
/*
Plugin Name: display-search-keywords
Plugin URI: http://www.imyxiao.com/1531.html
Description: 当访客通过搜索引擎来到你的博客,这个插件可以显示访客搜索的关键词
Version: 1.0
Author:<a href="http://www.imyxiao.com/">仰肖</a>
*/
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 .= $str[$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;
// 判断
if (isset ($search_engines[$ref])) {
$delim = $search_engines[$ref];
}
return $delim;
}
function ls_get_refer() {
// 判断前一页面的 URL 地址
$queryString = $_GET['referer'];
$queryString = unescape($queryString);
if (!isset ($queryString) || ($queryString == ''))
return false;
$referer_info = parse_url($queryString);
$referer = $referer_info['host'];
//去除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) {
//取得查询值
$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('<div id="serp"><p>')
document.write('更多搜索结果:<em><a href="https://www.jb51.net/search?q=<?php ls_getinfo(terms); ?>" ')
document.write('title="查看<?php ls_getinfo(terms); ?>的搜索结果" rel="nofollow"><?php ls_getinfo(terms); ?></a></em>')
document.write('</p></div>');
<?php } ?>
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 柏菲·胭花四乐《胭花四乐》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 群星《监听耳机天碟》2018[WAV分轨][1G]
- 群星《娱协奖原创金曲合辑》滚石[WAV+CUE][1.1G]
- 罗大佑《美丽岛》2CD[WAV+CUE][1.1G]
- 言承旭.2009-多出来的自由【SONY】【WAV+CUE】
- 赤道.2000-精选2CD【ACM】【WAV+UCE】
- 许廷铿.2017-神奇之旅【华纳】【WAV+CUE】
- 李克勤《罪人》环球[WAV+CUE][1G]
- 陈粒2024《乌有乡地图》有此山文化[FLAC分轨][1G]
- 蔡依林《MYSELF》 奢华庆菌版 2CD[WAV+CUE][1.5G]
- 刘春美《心与心寻世界名曲中文版》新京文[低速原抓WAV+CUE]
- 朱逢博《蔷薇蔷薇处处开》[FLAC+CUE]
- 姚璎格2005《心在哭泣》龙韵[WAV分轨]
- 费玉清《费玉清收藏》 2CD 华纳[WAV+CUE][1G]
- 徐怀钰《LOVE》台湾首版[WAV+CUE][1G]