关于x3.5版本获取真实IP
升级了论坛3.5版本,发现IP出现问题了;弄了两天,才弄好;
论坛自身是apache + php 5.6 的配置;
前面还有nginx代理;
正确配置如下;
1. 放开安全限制,ip接收其他参数头;
config/config_global.php
2. 修改ip相关配置参数;
3. nginx配置4. 测试文件
论坛自身是apache + php 5.6 的配置;
前面还有nginx代理;
正确配置如下;
1. 放开安全限制,ip接收其他参数头;
config/config_global.php
- $_config['security']['onlyremoteaddr'] = 0; //默认为1,表示只接受remote addr参数头;
- $_config['ipgetter']['setting'] = 'header';$_config['ipgetter']['header']['header'] = 'HTTP_X_REAL_IP';
3. nginx配置
- location / { client_max_body_size 1000m; proxy_pass http://10.1.9.5:8080; proxy_set_header Host $host:$server_port; //论坛非标准端口,代理时需要添加这个东东; proxy_set_header X-REAL-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
- <?phpclass ip_getter_header { public static function get($s) { if (empty($s['header'])) { return $_SERVER['REMOTE_ADDR']; } $ip = isset($_SERVER[$s['header']]) ? $_SERVER[$s['header']] : $_SERVER['REMOTE_ADDR']; return $ip; }}foreach ($_SERVER as $key => $value) { echo "$key: $value<br>";}$customHeader = 'aaaaa';$ip = ip_getter_header::get(['header' => $customHeader]);echo "<Br><Br>Client IP Address: " . $ip;$customHeader2 = 'HTTP_AAAAA';$ip2 = ip_getter_header::get(['header' => $customHeader2]);echo "<Br>Client IP Address2: " . $ip2;?>