Common program search keyword transcoding
Published: 2018-01-12
Some search-type websites may experience false blocking due to malicious user searches. Such websites themselves contain no illegal information; it is only because the search keywords are displayed on the web page (as shown below)
, you can refer to the following method to transcode the output keywords

DEDECMS program
This article covers search transcoding for the Dedecms program; the principle is similar for other programs: transcode the keywords in search results before outputting them
1: Check the website encoding. After accessing the backend, it will be displayed below, in two versions: GBK and UTF8

2: Copy the following code to the end of the include/extend.func.php file (Copy the corresponding code according to your website encoding; when editing web pages, it is recommended to use notepad or editplus software)
UTF-8 encoding
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 encoding
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;
}3: Modify the search template file templets/default/search.htm [The path may vary for other templates]
Find: {dede:global name='keyword' function='RemoveXSS(@me)'/}
Replace with: {dede:global name='keyword' function='CharCodeAt(RemoveXSS(@me))'/}
4: View the source code of the search page to check whether it takes effect

Discuz program, example for Discuz!X3.4 GBK version
1. Check the web page encoding
1. Right-click the web page and view the source code

2. Check $_config['output']['charset'] in config/config.php

2. According to the encoding, copy the CharCodeAt function above, modify the source/function/function_search.php file, and add it to the end of the file. Note that it should be before ?>

3. Modify the source/module/search/search_forum.php program
Add the following two lines of code at line 129
$keyword = CharCodeAt($keyword);
$modkeyword = CharCodeAt($modkeyword);

4. View the source code of the search page and check whether it takes effect
