Posted By

jprochazka on 10/02/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

noone453


Get a visitor's real IP address.


 / Published in: PHP
 

A more reliable way to obtain a visitor's IP address.

  1. <?php
  2. function getRealIp()
  3. {
  4. if (!empty($_SERVER['HTTP_CLIENT_IP'])){
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  8. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  9. }
  10. else{
  11. $ip=$_SERVER['REMOTE_ADDR'];
  12. }
  13. return $ip;
  14. }
  15.  
  16. ?>

Report this snippet  

You need to login to post a comment.