当前位置:Gxlcms > PHP教程 > 取得用户IP地址的PHP代码

取得用户IP地址的PHP代码

时间:2021-07-01 10:21:17 帮助过:4人阅读

  1. function getRealIpAddr()
  2. {
  3. if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
  4. {
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
  8. {
  9. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  10. }
  11. else
  12. {
  13. $ip=$_SERVER['REMOTE_ADDR'];
  14. }
  15. return $ip;
  16. }

PHP

人气教程排行