Posted By

mladoux on 09/22/10


Tagged

php security utility ip proxy


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

roli000


get_ip


 / Published in: PHP
 

URL: http://mark.haktstudios.com/

A simple IP address utility that first attempts to get the users IP via X_FORWARDED_FOR headers, and if they are not available, then resorts to the TCP/IP stack.

  1. /**
  2.  * get_ip()
  3.  *
  4.  * Attempts to retrieve the most accurate IP address possible.
  5.  *
  6.  * @return string - best IP address guess.
  7.  */
  8.  
  9. function get_ip()
  10. {
  11. if(isset($_SERVER['X_FORWARDED_FOR']))
  12. // fixed typo
  13. return trim(reset(explode(',', $_SERVER['X_FORWARDED_FOR'])));
  14. else return $_SERVER['REMOTE_ADDR'];
  15. }

Report this snippet  

You need to login to post a comment.