note 92412 added to function.getenv
| From: | f dot hartmann2 at gmx dot net | Date: | Thu, 23 Jul 2009 12:42:55 +0000 |
| Subject: | note 92412 added to function.getenv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158623@lists.php.net to get a copy of this message | ||
A function returning the remote adress of the visiting browser could look like this:
function getIPfromXForwarded() {
$ipString=@getenv("HTTP_X_FORWARDED_FOR");
$addr = explode(",",$ipString);
return $addr[sizeof($addr)-1];
}
Note that some adresses are followed by a whitespace and ip2long(getIPfromXForwarded()) would not
return the expected result.
Make use of trim() in your scripts, either in the function itself, or the surrounding space of the
caller.
Greetings
----
Server IP: 64.71.164.2
Probable Submitter: 89.61.243.210
----
Manual Page -- http://www.php.net/manual/en/function.getenv.php
Edit -- https://master.php.net/note/edit/92412
Del: integrated -- https://master.php.net/note/delete/92412/integrated
Del: useless -- https://master.php.net/note/delete/92412/useless
Del: bad code -- https://master.php.net/note/delete/92412/bad+code
Del: spam -- https://master.php.net/note/delete/92412/spam
Del: non-english -- https://master.php.net/note/delete/92412/non-english
Del: in docs -- https://master.php.net/note/delete/92412/in+docs
Del: other reasons-- https://master.php.net/note/delete/92412
Reject -- https://master.php.net/note/reject/92412
Search -- https://master.php.net/manage/user-notes.php