Skip to content

Instantly share code, notes, and snippets.

@oshanz
Created January 30, 2014 16:28
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 oshanz/8712560 to your computer and use it in GitHub Desktop.
Save oshanz/8712560 to your computer and use it in GitHub Desktop.
php get ip
function getUserIpAddr() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //if from shared
return $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //if from a proxy
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