Re: Wrong IP address
| From: | K.Bogac Bokeer | Date: | Fri, 02 Apr 2004 12:23:37 +0000 |
| Subject: | Re: Wrong IP address | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182116@lists.php.net to get a copy of this message | ||
I'm using this one:
function FetchIP() {
$client_ip = $_SERVER['HTTP_CLIENT_IP'];
$x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR'];
$remote_addr = $_SERVER['REMOTE_ADDR'];
if ( !empty ($client_ip) ) {
$ip_expl = explode('.',$client_ip);
$referer = explode('.',$remote_addr);
if($referer[0] != $ip_expl[0]) {
$ip=array_reverse($ip_expl);
$return=implode('.',$ip);
} else {
$return = $client_ip;
};
} elseif ( !empty($x_forwarded_for) ) {
if(strstr($x_forwarded_for,',')) {
$ip_expl = explode(',',$x_forwarded_for);
$return = end($ip_expl);
} else {
$return = $x_forwarded_for;
};
} else {
$return = $remote_addr;
};
unset ($client_ip, $x_forwarded_for, $remote_addr, $ip_expl);
return $return;
}
Ascll wrote:
Greetings, I make use of these: - <?php echo($_SERVER["REMOTE_ADDR"]); ?> to get the web IP address for my machine once my PC is connected to Internet.. Anyway, sometime I get the correct IP address, but sometime NOT. Does anyone know why? Thanks in advance.