Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get the real IP address of the client and optionally also the one from the proxy server.
* Get the IP address of the client.
* @author Arno Moonen <>
* @version 0.1-201112231035
* @param boolean $get_all Set to true to get an array containing all the IP addresses found.
* @return mixed Depending on the value of $get_all the return value will be either a string or an array
function am_get_real_ip($get_all = false)
$keys = array(
$ips = array();
foreach ($keys as $X) {
if (array_key_exists($X, $_SERVER) && !empty($_SERVER[$X])) {
if (!$get_all) {
return $_SERVER[$X];
$ips[$X] = $_SERVER[$X];
return array_unique($ips, SORT_STRING);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment