allthebest 發表於 2019-7-18 20:06:55

Discuz! x 3或以上版本 ,游客搜索不了的解决方法!

<br /><br />游客时,在未登录的状态下搜索 出现”您当前的访问请求当中含有非法字符,已经被系统拒绝“错误。<br /><br />解决方案<br /><br />查看代码<br /><br />\source\class\discuz的discuz_application.php<br /><ol><li>private function _xss_check() {<br /><li> <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; static $check = array('&quot;', '&gt;', '&lt;', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');<br /><li> <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(isset($_GET['formhash']) &amp;&amp; $_GET['formhash'] !== formhash()) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;system_error('request_tainting');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li> <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if($_SERVER['REQUEST_METHOD'] == 'GET' ) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$temp = $_SERVER['REQUEST_URI'];<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; } elseif(empty ($_GET['formhash'])) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$temp = $_SERVER['REQUEST_URI'].file_get_contents('php://input');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; } else {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$temp = '';<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li> <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(!empty($temp)) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$temp = strtoupper(urldecode(urldecode($temp)));<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;foreach ($check as $str) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(strpos($temp, $str) !== false) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; system_error('request_tainting');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li> <br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return true;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}</ol><br /><br />替换为以下代码<br /><br /><ol><li>private function _xss_check() {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $temp = strtoupper(urldecode(urldecode($_SERVER['REQUEST_URI'])));<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(strpos($temp, '&lt;') !== false || strpos($temp, '&quot;') !== false || strpos($temp, 'CONTENT-TRANSFER-ENCODING') !== false) {<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;system_error('request_tainting');<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return true;<br /><li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}</ol><br /><br />更新缓存后测试看看。<br /><br /><br />游客<em>, </em>搜索<em>, </em>discuz<em>, </em>本帖<em>, </em>最后

wuyou 發表於 2019-7-18 22:11:54

<br /><br />所有论坛都是游客不能搜索,这个DZ程序自己的问题,我也试下楼主的这个解决方案。<br /><br />通过以上方法,确实解决了DZ游客搜索的问题, 感谢哈。<br /><br /><br />

allthebest 發表於 2019-7-19 00:09:19

<br />Discuz! X 2.5或以下版本,游客搜索没问题。<br /><br />我自己测试,Discuz! x 3.2 或以后版本,游客搜索都会出现错误提示。<br /><br />要修改一下程序,游客才能搜索啊!

yehui2512 發表於 2019-7-19 19:04:28

不错,收藏了,为何这么久了官方一直不更新。

allthebest 發表於 2019-7-19 19:21:21

<br />让游客搜索,免注册;论坛想兴旺也难。相信这是官方不重视原因吧!

yehui2512 發表於 2019-7-19 20:30:33

<br />不是为了让游客搜索。而是出个好看的、友好的“界面提示”。<br /><br />下面这样的确实不好看吧。<br /><img title="ddd.png" id="aimg_1627" aid="1627" src1="static/image/common/none.gif" zoom="https://www.dismall.com/data/attachment/forum/201907/19/203028ei0lrzmcz3mvce3d.png" src="https://www.dismall.com/data/attachment/forum/201907/19/203028ei0lrzmcz3mvce3d.png" class="zoom" onclick="zoom(this, this.src, 0, 0, 0)" width="600" inpost="1" onmouseover="showMenu({'ctrlid':this.id,'pos':'12'})" /><br />

allthebest 發表於 2019-7-19 20:51:02

<br />作为站长,没必要用游客身份去搜索。<br /><br />当游客搜索只看到不明白页面讯息,又不能发短消息或发帖提问<br />要问或要搜索,就自然会注册<br /><br />注册用户才能发帖,帖子多才能引入更多游客访问;日子久了,会员才多起来,论坛才能兴旺火起来呢!<br />

wuyou 發表於 2019-7-19 22:11:13

哈哈,游客不让搜索,不符合用户体验。

yehui2512 發表於 2019-7-19 22:17:33

<br /><br />直接出现 ”您当前的访问请求当中含有非法字符,已经被系统拒绝“<br /><br />再加上几条PHP错误。<br /><br />对普通游客,是不是太暴力了。。<br /><br /><br />

yehui2512 發表於 2019-7-19 22:19:07

可以改为提示,需要注册成为用户才能使用搜索功能啊。用户一点“注册”,直接引导到注册页面,不是更好么。
頁: [1]
查看完整版本: Discuz! x 3或以上版本 ,游客搜索不了的解决方法!