怎么查询使用CDN后Discuz论坛网站真实IP地址的方法
使用了国外的空间的站长经常会苦恼空间访问速度慢,DNS解析反应慢的问题。为了解决这些问题,最好的办法就是使用CDN,加快博客和网站从国内的访问速度,提高用户体验度。高速度
(www.gaosudu.com)小编发现最近有客户说使用了加速乐等CDN产品之后无法获得客户的真实IP,这种情况在高速度
小编找了很久之后才发现问题的解决方法,而且适合DZ使用任何一种CDN产品之后照成的这种情况。首先说手该问题导致的结果:1.Discuz论坛可能无法获得用户的真实IP,导致某些用户IP显示的是CDN产品节点的IP2.论坛访问量过大的话,可能会导致用户访问时提示“抱歉,您的 IP 地址不在被允许,或您的账号被禁用,无法访问本站点” 接下来谈谈产生原因:使用CDN,对于网站访客来说,相当于使用了代理访问,而DZ在设计上,是优先获取代理IP,其它才会检测代理服务器是否将用户真实IP传输过来,也就是说获取代理IP优先于用户真实IP。如果您的网站不需要对用户访问做过多的限制,强烈建议按照以下方法进行:第一种(DZ X2版本):打开DZ,/source/class/class_core.php 文件;搜索“HTTP_CLIENT_IP”,找到下面这段代码:function _get_client_ip() {$ip = $_SERVER['REMOTE_ADDR'];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'], $matches)) {foreach ($matches[0] AS $xip) {if (!preg_match(‘#^(10|172.16|192.168).#’, $xip)) {$ip = $xip;break;}}}return $ip;}替换成一下代码:function _get_client_ip() {$ip = $_SERVER['REMOTE_ADDR'];if (isset($_SERVER['HTTP_X_REAL_FORWARDED_FOR']) && preg_match(‘/^([0-9]{1,3}.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_X_REAL_FORWARDED_FOR'])) {$ip = $_SERVER['HTTP_X_REAL_FORWARDED_FOR'];}elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match(‘/^([0-9]{1,3}.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_X_FORWARDED_FOR'])) {$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];}elseif (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'];}return $ip;} 第二种(Discuz! 2.5/Discuz! 3.0):private function _get_client_ip() {$ip = $_SERVER['REMOTE_ADDR'];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'], $matches)) {foreach ($matches[0] AS $xip) {if (!preg_match(‘#^(10|172.16|192.168).#’, $xip)) {$ip = $xip;break;}}}return $ip;}替换成一下代码:private function _get_client_ip() {$ip = $_SERVER['REMOTE_ADDR'];if (isset($_SERVER['HTTP_X_REAL_FORWARDED_FOR']) && preg_match(‘/^([0-9]{1,3}.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_X_REAL_FORWARDED_FOR'])) {$ip = $_SERVER['HTTP_X_REAL_FORWARDED_FOR'];}elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && preg_match(‘/^([0-9]{1,3}.){3}[0-9]{1,3}$/’, $_SERVER['HTTP_X_FORWARDED_FOR'])) {$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];}elseif (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'];}return $ip;}以上操作后,登陆您的CDN加速产品后台和你的Discuz论坛后台分别清除缓存即可。纯Linux环境下高端免备案【香港独立IP地址】 php空间,仅仅只需199元一年起。全网最低价域名感恩广大新老客户,首年只要39元。
本文地址:https://www.gaosudu.com/discuz/11675.html