A function to get the real IP address.

/ Published in: PHP

This function performs several checks to make sure it's getting the correct IP address.

Copy this code and paste it in your HTML
  1. function get_ip(){
  2. if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } // Check if the IP is from a shared internet connection
  3. else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } // Check if the IP is passed from a proxy
  4. else{ $ip = $_SERVER['REMOTE_ADDR']; } // The real IP address
  5. return $ip;
  6. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.