----- Original Message -----
From: "David Calkins" <dcalk@xxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Monday, March 13, 2006 2:20 AM
Subject: determining client's external IP
My web page needs to determine the client's external IP address, i.e., the
IP address that others viewing the web page would be able to use to
contact
that user's machine (assuming they've setup the appropriate forwarding
into
their actual machine of course). In this environment the clients want
their external
IP to be correctly reported, so there's no issue of people trying to spoof
and
show a wrong IP.
I'm currently using $_SERVER['REMOTE_ADDR'] as this seemed like the best
approach as I thought it would yield the IP as seen from the web server
and
hence, hopefully, as seen by everyone else on the internet.
This works in many cases, but in a couple cases users have reported issues
with others not being able to use the IPs the web page reports to contact
their
machines. In these cases the $_SERVER['REMOTE_ADDR'] seems to be
returning
a different IP than what www.whatismyip.com <http://www.whatismyip.com>
returned, for example.
Is there another reccomended way to get the client's externally visible IP
address? Or is $_SERVER['REMOTE_ADDR'] the right approach but might
not always work?
Thanks!
Due to the shortage of IP addresses (there are only 32bits, with gaps of
unused addresses in between and there are many more devices than ever
thought possible), IP addresses are reused. ISP translate the IP addresses
clients use within their network to any of the pool of valid IP addresses
they have licensed from ICANN. This assignment is dynamic and quite
unpredictable, it might change every single day, it might be stable for
months and change suddenly. It depends on the ISP, nothing you can do on
your side, what you are getting now is as good as you'll ever get.
Both HTTP proxies and routers with NAT (Network Address Translation) do this
automatically. Outside addresses obtained from devices that reach the
outside world through any of these devices are not reachable from the
outside, you cannot connect to any service they might be offering, because
the translation does not work backwards.
Satyam
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php