note 92412 modified in function.getenv by thiago
| From: | thiago@php.net | Date: | Thu, 23 Jul 2009 13:39:33 +0000 |
| Subject: | note 92412 modified in function.getenv by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158625@lists.php.net to get a copy of this message | ||
A function returning the remote adress of the visiting browser could look like this:
<?php
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
--was--
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
http://php.net/manual/en/function.getenv.php