当前位置:Gxlcms > PHP教程 > PHP获取访问者IP地址

PHP获取访问者IP地址

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

获取访问者IP地址

[PHP]代码

  1. static public function getip()
  2. {
  3. if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
  4. {
  5. $ip = getenv("HTTP_CLIENT_IP");
  6. }
  7. else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
  8. {
  9. $ip = getenv("HTTP_X_FORWARDED_FOR");
  10. }
  11. else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
  12. {
  13. $ip = getenv("REMOTE_ADDR");
  14. }
  15. else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
  16. {
  17. $ip = $_SERVER['REMOTE_ADDR'];
  18. }
  19. else
  20. {
  21. $ip = "";
  22. }
  23. return($ip);
  24. }
PHP

人气教程排行