note 30232 deleted from function.getenv by philip

From: Date: Mon, 09 Jun 2003 21:02:00 +0000
Subject: note 30232 deleted from function.getenv by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-50056@lists.php.net to get a copy of this message
Note Submitter: winther@anders.dk ---- My "bullet-proof" solution to fetch an IP-address.. <? function iptype1 () { if (getenv("HTTP_CLIENT_IP")) { return getenv("HTTP_CLIENT_IP"); } else { return "none"; } } function iptype2 () { if (getenv("HTTP_X_FORWARDED_FOR")) { return getenv("HTTP_X_FORWARDED_FOR"); } else { return "none"; } } function iptype3 () { if (getenv("REMOTE_ADDR")) { return getenv("REMOTE_ADDR"); } else { return "none"; } } function ip() { $ip1 = iptype1(); $ip2 = iptype2(); $ip3 = iptype3(); if (isset($ip1) && $ip1 != "none" && $ip1 != "unknown") { return $ip1; } elseif (isset($ip2) && $ip2 != "none" && $ip2 != "unknown") { return $ip2; } elseif (isset($ip3) && $ip3 != "none" && $ip3 != "unknown") { return $ip3; } else { return "none"; } } $ip = ip(); ?> I've fetched around 600 unique IP-addresses with this approach.. None of them returned "none" or "unknown".. Only real IP-addresses. Best regards Anders Winther

« previous php.notes (#50056) next »