Home  >  Article  >  Backend Development  >  PHP gets user’s real IP

PHP gets user’s real IP

WBOY
WBOYOriginal
2016-07-25 08:42:40824browse
  1. function getRealIpAddr()
  2. {
  3. if (!emptyempty($_SERVER['HTTP_CLIENT_IP']))
  4. {
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR']))
  8. //to check ip is pass from proxy
  9. {
  10. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  11. }
  12. else
  13. {
  14. $ip=$_SERVER['REMOTE_ADDR'];
  15. }
  16. return $ip;
  17. }
复制代码

用法:

  1. $ip = getRealIpAddr();
  2. echo $ip;
  3. ?>
复制代码

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