個別搜索類的網站因為用戶惡意搜索出現誤攔截情況,這類網站本身沒有非法信息,只是因為把搜索關鍵字顯示在網頁中(如下圖),可以參考下面方法對輸出的關鍵字進行轉碼
DEDECMS程序?
本文針對Dedecms程序進行搜索轉碼,其它程序原理類似:對搜索結果的關鍵字進行轉碼后輸出
一:查看網站編碼,訪問后臺下面會顯示,GBK和UTF8兩個版本
二:復制下面代碼到 include/extend.func.php 文件尾部(根據您的網站編碼復制對應的代碼,編輯網頁時推薦使用notepad、editplus軟件)
?UTF-8編碼
function?CharCodeAt($str) {$strr="";for($i=0;$i<mb_strlen($str,'utf-8');$i++){$char?=?mb_substr($str,$i,1,?'UTF-8');if?(mb_check_encoding($char,?'UTF-8')){$ret?=?mb_convert_encoding($char,?'UTF-32BE',?'UTF-8');$strr.="&#".hexdec(bin2hex($ret));}else{return?null;}}return?$strr; }
GBK編碼
function?CharCodeAt($str) {$strr="";for($i=0;$i<mb_strlen($str,'gb2312');$i++){$char?=?mb_substr($str,$i,1,?'gb2312');if?(mb_check_encoding($char,?'gb2312')){$ret?=?mb_convert_encoding($char,?'UTF-32BE',?'gb2312');$strr.="&#".hexdec(bin2hex($ret));}else{return?null;}}return?$strr; }
三:修改搜索模板文件templets/default/search.htm? 【其它模板可能路徑會有變化】
找到: {dede:global name='keyword' function='RemoveXSS(@me)'/}
替換成:{dede:global name='keyword' function='CharCodeAt(RemoveXSS(@me))'/}
四:查看搜索頁源代碼,查看是否生效
Discuz 程序,示例針對Discuz!X3.4 ?GBK版本
一、查看網頁編碼
????????1.網頁右鍵查看源代碼
????????
?????????2.查看config/config.php 的$_config['output']['charset']
????????
二、根據編碼復制上面的CharCodeAt函數,修改?source/function/function_search.php 文件,加到文件尾部,注意在?> 前面
????????
三、修改source/module/search/search_forum.php 程序?
在129行添加如下兩行代碼?
$keyword = CharCodeAt($keyword);
$modkeyword = CharCodeAt($modkeyword);
四、查看搜索頁源代碼,檢查是否生效
?????
原文鏈接:https://www.west.cn/faq/list.asp?unid=1952?