note 66181 deleted from function.gethostbyaddr by bjori
| From: | bjori@php.net | Date: | Tue, 16 May 2006 21:56:37 +0000 |
| Subject: | note 66181 deleted from function.gethostbyaddr by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-111417@lists.php.net to get a copy of this message | ||
Note Submitter: alex at noinc
Reason: bad code
----
here is a handy little func , can be used with gethostbyaddr like it comes stock ...if you like that
func .. or u can drop in one of the replacements the other comments above have noted ...
this one is nice because it will do one of the following depending on what's available:
1. "hostname (IP) @ proxy host (proxy IP)"
2. "IP @ proxy IP"
3. "hostname (IP)"
4. "IP"
i.e. it will give u whatever it can get ...with bare minimum being IP only
function host_info() {
global $HTTP_SERVER_VARS;
if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"] != ""){
$IP = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
$proxy_IP = $HTTP_SERVER_VARS["REMOTE_ADDR"];
$proxy_host = @gethostbyaddr($HTTP_SERVER_VARS["REMOTE_ADDR"]);
$host = @gethostbyaddr($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]);
} else {
$IP = $HTTP_SERVER_VARS["REMOTE_ADDR"];
$host = @gethostbyaddr($HTTP_SERVER_VARS["REMOTE_ADDR"]);
}
if ($host != $IP)
$host = "$host ($IP)";
if (isset($proxy_host)) {
$host .= ' @' . $proxy_host;
if ($proxy_host != $proxy_IP)
$host .= " ($proxy_IP)";
}
return $host;
}