acctman Posted July 29, 2008 Share Posted July 29, 2008 are these all the combinations for getting a users IP function getIP() { 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; } Link to comment https://forums.phpfreaks.com/topic/117082-getip-function/ Share on other sites More sharing options...
gorgo666 Posted July 29, 2008 Share Posted July 29, 2008 I don't quite understand your question, but I was sure that REMOTE_ADDR was the only thing you needed to do, as you put there. Link to comment https://forums.phpfreaks.com/topic/117082-getip-function/#findComment-602177 Share on other sites More sharing options...
chad101 Posted July 29, 2008 Share Posted July 29, 2008 $_SERVER <?php function getip() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip_addr = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip_addr = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip_addr = $_SERVER["REMOTE_ADDR"]; } } else { if (getenv('HTTP_X_FORWARDED_FOR')) { $ip_addr = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif (getenv('HTTP_CLIENT_IP')) { $ip_addr = getenv('HTTP_CLIENT_IP'); } else { $ip_addr = getenv('REMOTE_ADDR'); } } return $ip_addr; } ?> Link to comment https://forums.phpfreaks.com/topic/117082-getip-function/#findComment-602182 Share on other sites More sharing options...
Goldeneye Posted July 29, 2008 Share Posted July 29, 2008 $_SERVER['HTTP_X_FORWARDED_FOR'] is usually used to detecting if a user is behind a proxy $_SERVER['HTTP_CLIENT_IP'] I believe, is what the user's real IP address is IF they are behind a proxy. So if you don't care about proxies, $_SERVER['REMOTE_ADDR'] will do just fine. Link to comment https://forums.phpfreaks.com/topic/117082-getip-function/#findComment-602187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.