note 32498 added to function.getenv
| From: | Joenema at aol dot com | Date: | Thu, 29 May 2003 08:25:47 +0000 |
| Subject: | note 32498 added to function.getenv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49242@lists.php.net to get a copy of this message | ||
This is just a reply to Anders Winther's fool-proof IP address fetcher.
What he has is good, but uses a lot of superfluous lines. Basically, he could have done this:
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;
}
Do you see how those numerous lines of code compressed into a few lines?
----
Manual Page -- http://www.php.net/manual/en/function.getenv.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32498
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32498&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32498&report=yes