Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rodrigoalviani
Created December 26, 2014 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigoalviani/d625ed428d244a6ed3bc to your computer and use it in GitHub Desktop.
Save rodrigoalviani/d625ed428d244a6ed3bc to your computer and use it in GitHub Desktop.
Get real user IP (PHP)
function ip() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== FALSE) {
$ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return trim(end($ip));
} else {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
} else {
return $_SERVER['REMOTE_ADDR'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment