note 40554 deleted from function.gethostbyaddr by nlopess
| From: | nlopess@php.net | Date: | Mon, 08 Mar 2004 17:12:44 +0000 |
| Subject: | note 40554 deleted from function.gethostbyaddr by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66443@lists.php.net to get a copy of this message | ||
Note Submitter: andy@occ.be
----
in reply to: info at widebore dot com
about the only thing that is present in the REMOTE_ADDR variable is IP's, and they're
seperated by a comma. (the only exception is "unknown", which is placed there if a user
is behind a proxy that does not show the http_x_forwarded_for)
so while you solution is a good one (the @ in front of the function) you could (very easily) go thru
that variable and parse it.
<?php
$remote = $_SERVER["REMOTE_ADDR"];
if (strstr($remote, ","){
$remote_array = explode(",", $remote);
foreach ($remote_array as $ip){
$hostname_array = @gethostbyaddr($ip);
}
}else{
$hostname = @gethostbyaddr($remote);
}
?>
also, the *real* IP should be the last IP in remote_addr; so you could do as in the above example
but only get the IP of the last in the array (<?php $hostname =
@gethostbyaddr(end($remote_array)); ?>)
ps: all code is untested