Posted By

paulgrenwood on 09/23/09


Tagged

php ip ipAddress


Versions (?)

Get Real IP Address of Client


 / Published in: PHP
 

This function will fetch the real IP address of the user even if he is behind a proxy server.

  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. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: giak on January 14, 2010

alternative : function neo_get_ip () { if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }

You need to login to post a comment.