获取ip地址
()
| 8 | |
| 9 | // 获取ip地址 |
| 10 | function getClientIp() |
| 11 | { |
| 12 | if (!empty($_SERVER['HTTP_X_REAL_IP'])) { |
| 13 | // nginx 代理模式下,获取客户端真实IP |
| 14 | $ip_address = $_SERVER['HTTP_X_REAL_IP']; |
| 15 | } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { |
| 16 | // 客户端的ip |
| 17 | $ip_address = $_SERVER['HTTP_CLIENT_IP']; |
| 18 | } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 19 | // 浏览当前页面的用户计算机的网关 |
| 20 | $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
| 21 | $pos = array_search('unknown', $arr); |
| 22 | if (false !== $pos) { |
| 23 | unset($arr[$pos]); |
| 24 | } |
| 25 | $ip_address = trim($arr[0]); |
| 26 | } else { |
| 27 | $ip_address = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; |
| 28 | } |
| 29 | return $ip_address; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * 根据ip获取客户端语言 |