Skip to content

Instantly share code, notes, and snippets.

@oshanz oshanz/php get ip
Created Jan 30, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.