Skip to content

Instantly share code, notes, and snippets.

@wangshijun wangshijun/ip.php forked from MilkZoft/ip.php
Created Sep 11, 2012

Embed
What would you like to do?
php: get user ip address
<?php
function get_client_ip() {
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
if(isset($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
} else {
return $_SERVER["REMOTE_ADDR"];
}
return $_SERVER["HTTP_X_FORWARDED_FOR"];
} else {
if(isset($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
} 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.