/ Published in: PHP
This function performs several checks to make sure it's getting the correct IP address.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function get_ip(){ if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } // Check if the IP is from a shared internet connection else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } // Check if the IP is passed from a proxy else{ $ip = $_SERVER['REMOTE_ADDR']; } // The real IP address return $ip; }