Posted By

Eloi on 04/23/09


Tagged

php ip


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Eloi
heinz1959
vali29


Function getIP


 / Published in: PHP
 

  1. function getIP(){
  2. if( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] )) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  3. else if( isset( $_SERVER ['HTTP_VIA'] )) $ip = $_SERVER['HTTP_VIA'];
  4. else if( isset( $_SERVER ['REMOTE_ADDR'] )) $ip = $_SERVER['REMOTE_ADDR'];
  5. else $ip = null ;
  6. return $ip;
  7. }
  8.  
  9. function getRealIpAddr()
  10. {
  11. if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
  12. {
  13. $ip=$_SERVER['HTTP_CLIENT_IP'];
  14. }
  15. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
  16. {
  17. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  18. }
  19. else
  20. {
  21. $ip=$_SERVER['REMOTE_ADDR'];
  22. }
  23. return $ip;
  24. }

Report this snippet  

You need to login to post a comment.