Posted By

michaJlS on 06/10/11


Tagged

ip host


Versions (?)

Obtaining IP and host of visitor


 / Published in: PHP
 

This piece of code is at least ten years old and I don't remember exactly, where I have found it. Probably it had been stolen from my friend VeZyR;)

  1. $ip=NULL; $host = '';
  2. if( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) $ip=$_SERVER["HTTP_X_FORWARDED_FOR"];
  3. if( $ip==NULL && isset($_SERVER["REMOTE_ADDR"]) ) $ip = $_SERVER["REMOTE_ADDR"];
  4. else
  5. {
  6. $ip_tab = explode(".", $ip);
  7. if($ip_tab[0]=="192" && $ip_tab[1]=="168") $ip = $_SERVER["REMOTE_ADDR"];
  8. }
  9. if($ip!=null) $host = gethostbyaddr($ip);
  10. else $ip = false;

Report this snippet  

You need to login to post a comment.