Skip to main content
Replaced TABs with spaces. Reformatted the sample code.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

I like this codesnippet:

function getClientIP() {  if (isset($_SERVER)) {   if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))   return $_SERVER["HTTP_X_FORWARDED_FOR"];      if (isset($_SERVER["HTTP_CLIENT_IP"]))   return $_SERVER["HTTP_CLIENT_IP"];   return $_SERVER["REMOTE_ADDR"];  }  if (getenv('HTTP_X_FORWARDED_FOR'))   return getenv('HTTP_X_FORWARDED_FOR');  if (getenv('HTTP_CLIENT_IP'))   return getenv('HTTP_CLIENT_IP');  return getenv('REMOTE_ADDR'); } 

I like this codesnippet:

function getClientIP() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) return $_SERVER["HTTP_X_FORWARDED_FOR"];    if (isset($_SERVER["HTTP_CLIENT_IP"])) return $_SERVER["HTTP_CLIENT_IP"]; return $_SERVER["REMOTE_ADDR"]; } if (getenv('HTTP_X_FORWARDED_FOR')) return getenv('HTTP_X_FORWARDED_FOR'); if (getenv('HTTP_CLIENT_IP')) return getenv('HTTP_CLIENT_IP'); return getenv('REMOTE_ADDR'); } 

I like this codesnippet:

function getClientIP() {  if (isset($_SERVER)) {   if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]))   return $_SERVER["HTTP_X_FORWARDED_FOR"];   if (isset($_SERVER["HTTP_CLIENT_IP"]))   return $_SERVER["HTTP_CLIENT_IP"];   return $_SERVER["REMOTE_ADDR"];  }  if (getenv('HTTP_X_FORWARDED_FOR'))   return getenv('HTTP_X_FORWARDED_FOR');  if (getenv('HTTP_CLIENT_IP'))   return getenv('HTTP_CLIENT_IP');  return getenv('REMOTE_ADDR'); } 
Post Merged (destination) from stackoverflow.com/questions/55768/…
Source Link

I like this codesnippet:

function getClientIP() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) return $_SERVER["HTTP_X_FORWARDED_FOR"]; if (isset($_SERVER["HTTP_CLIENT_IP"])) return $_SERVER["HTTP_CLIENT_IP"]; return $_SERVER["REMOTE_ADDR"]; } if (getenv('HTTP_X_FORWARDED_FOR')) return getenv('HTTP_X_FORWARDED_FOR'); if (getenv('HTTP_CLIENT_IP')) return getenv('HTTP_CLIENT_IP'); return getenv('REMOTE_ADDR'); }