Skip to content

Instantly share code, notes, and snippets.

@rkmaier
Created March 14, 2012 16:51
Show Gist options
  • Save rkmaier/2037822 to your computer and use it in GitHub Desktop.
Save rkmaier/2037822 to your computer and use it in GitHub Desktop.
PHP::Get Client IP adress
<?php
function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "UNKNOWN";
return $ip;
}
@aaronwp
Copy link

aaronwp commented Mar 14, 2012

Nice job! Exactly what I needed. Works in Rackspace Cloud environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment