现象:
1.DZ论坛可能无法获得用户的真实IP
2.论坛访问量过大的话,可能会导致用户访问时提示“抱歉,您的 IP 地址不在被允许,或您的账号被禁用,无法访问本站点”
原因:
使用CDN,对于网站访客来说,相当于使用了代理访问,而DZ在设计上,是优先获取代理IP,其它才会检测代理服务器是否将用户真实IP传输过来,也就是说获取代理IP优先于用户真实IP。如果您的网站不需要对用户访问做过多的限制,强烈建议按照以下方法进行:
解决方法(DZ X2为例):
打开DZ /source/class/class_core.php 文件
找到第341行,或者搜索“HTTP_CLIENT_IP”,找到如下代码:- if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match(‘/^([0-9]{1,3}\.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all(‘#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s’, $_SERVER['HTTP_X_FORWARDED_FOR'],
- if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match(‘/^([0-9]{1,3}\.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all(‘#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s’, $_SERVER['HTTP_X_FORWARDED_FOR'],
复制代码 方法1:
将以上代码修改为:- if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all(‘#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s’, $_SERVER['HTTP_X_FORWARDED_FOR'],
- if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all(‘#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s’, $_SERVER['HTTP_X_FORWARDED_FOR'],
复制代码 方法2:
临时注释部分代码,也就是比原来的代码多了二对注释符(/*和*/)即将上面的代码修改成:- /*
- if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match(‘/^([0-9]{1,3}\.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } else
- */
- if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all(‘#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s’, $_SERVER['HTTP_X_FORWARDED_FOR'],
- /*
- if (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match(‘/^([0-9]{1,3}\.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }else
- */
- if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all(‘#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s’, $_SERVER['HTTP_X_FORWARDED_FOR'],
复制代码 以上操作后,登陆CDN和你的Discuz!论坛后台分别清除缓存即可。
备注:部分版本的Discuz!该文件中可能有区别,
方法来自加速乐,原文地址:http://bbs.jiasule.com/thread-4-1-1.html
|