Skip to content

Instantly share code, notes, and snippets.

@plasticbrain
Created September 28, 2012 06:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plasticbrain/3798262 to your computer and use it in GitHub Desktop.
Save plasticbrain/3798262 to your computer and use it in GitHub Desktop.
PHP: Get user's real IP address
function get_ip() {
if( isset($_SERVER['HTTP_CLIENT_IP']) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif( isset($_SERVER['HTTP_X_FORWARDED_FOR']) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = @$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment