The following code is used to get ip address by using PHP
get_ip_address()
(Custom function by John)
get_ip_address -- Retrieves Ip adres from user and checks for proxy server.
Description
(string) get_ip_address()
This simple function checkes whether the uses is behind a (transparent) proxy, and returns the found IP adres.
Function
function get_ip_address()
{
if (isset($_SERVER)) {
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && ip2long($_SERVER["HTTP_X_FORWARDED_FOR"]) !== false) {
$ipadres = $_SERVER["HTTP_X_FORWARDED_FOR"];
} elseif (isset($_SERVER["HTTP_CLIENT_IP"]) && ip2long($_SERVER["HTTP_CLIENT_IP"]) !== false) {
$ipadres = $_SERVER["HTTP_CLIENT_IP"];
} else {
$ipadres = $_SERVER["REMOTE_ADDR"];
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR') && ip2long(getenv('HTTP_X_FORWARDED_FOR')) !== false) {
$ipadres = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('HTTP_CLIENT_IP') && ip2long(getenv('HTTP_CLIENT_IP')) !== false) {
$ipadres = getenv('HTTP_CLIENT_IP');
} else {
$ipadres = getenv('REMOTE_ADDR');
}
}
return $ipadres;
}
?>
0 comments:
Post a Comment