Forum Moderators: coopster

Message Too Old, No Replies

How do i extend this showIP?

ShowIP

         

john1000

2:34 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



Hello,

I wanna show the visitors IP on a page and the basic one i use is this:
<?php
echo "IP Address: " . $_SERVER['REMOTE_ADDR'] . "<br>"; // Display IP address
?>

Who can tell me how to extend this so it will always show the correct ip.....also when they use a proxy..!

barns101

3:53 pm on Nov 2, 2006 (gmt 0)

10+ Year Member



The proxy variables that I know of are $_SERVER[HTTP_X_FORWARDED_FOR], $_SERVER[HTTP_VIA], and $_SERVER[HTTP_PROXY_CONNECTION]. If they are using an anonymous proxy you wont get their actual IP address.

john1000

1:25 am on Nov 3, 2006 (gmt 0)

10+ Year Member



But how do i put that all into 1 script?

Vastio

4:06 am on Nov 3, 2006 (gmt 0)

10+ Year Member




function visitorIP() {
$ipParts = explode(".", $_SERVER['REMOTE_ADDR']);
if ($ipParts[0] == "165" && $ipParts[1] == "21") {
if (getenv("HTTP_CLIENT_IP")) {
$ip = getenv("HTTP_CLIENT_IP");
} elseif (getenv("HTTP_X_FORWARDED_FOR")) {
$ip = getenv("HTTP_X_FORWARDED_FOR");
} elseif (getenv("REMOTE_ADDR")) {
$ip = getenv("REMOTE_ADDR");
}
} else {
return $_SERVER['REMOTE_ADDR'];
}
return $ip;
}

echo "IP Address: " . visitorIP() . "<br>"; // Display IP address

john1000

11:40 am on Nov 3, 2006 (gmt 0)

10+ Year Member



thanks Vastio..
That looks great..
question,what does this do?
>>>if ($ipParts[0] == "165" && $ipParts[1] == "21") { <<<

Vali

6:35 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



checks if the ip starts with 165.21

john1000

9:06 pm on Nov 3, 2006 (gmt 0)

10+ Year Member



And why is that?

john1000

3:17 pm on Nov 5, 2006 (gmt 0)

10+ Year Member



anyone?

coopster

11:19 pm on Nov 6, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Must have been a specific proxy that Vastio was checking for one reason or another. If not, just return the full IP as it was sent.

john1000

11:29 pm on Nov 6, 2006 (gmt 0)

10+ Year Member



so should i leave it or take it out?