Obtaining IP and host of visitor


/ Published in: PHP
Save to your folder(s)

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;)


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.