PHP gets real IP even if he uses proxy

WBOY
Release: 2016-07-25 08:42:00
Original
974 people have browsed it
[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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template