Last active
September 6, 2015 15:19
-
-
Save vhdm/12e54e50f1d4dbc7a3e2 to your computer and use it in GitHub Desktop.
Get ip address in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment