Home  >  Article  >  Backend Development  >  PHP gets real IP even if he uses proxy

PHP gets real IP even if he uses proxy

WBOY
WBOYOriginal
2016-07-25 08:42:00956browse
[PHP] Code
  1. function getRealIpAddr()
  2. {
  3. if (!empty($_SERVER['HTTP_CLIENT_IP']))
  4. {
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!empty ($_SERVER['HTTP_X_FORWARDED_FOR']))
  8. //Check the IP is passed from the proxy
  9. {
  10. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  11. }
  12. else
  13. {
  14. $ip=$_SERVER['REMOTE_ADDR'] ;
  15. }
  16. return $ip;
  17. }
Copy code
PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn