PHP获取真实IP,即便他使用代理
时间:2021-07-01 10:21:17
帮助过:6人阅读
[PHP]代码 - function getRealIpAddr()
- {
- if (!empty($_SERVER['HTTP_CLIENT_IP']))
- {
- $ip=$_SERVER['HTTP_CLIENT_IP'];
- }
- elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
- //检查IP是从代理传递
- {
- $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- else
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
|
PHP