tags:

views:

488

answers:

3

Hai Guys, How to get wan ip address of my user using php....

+1  A: 

Look at the question asked just 15 minutes ago about the same thing. There is your answer.
Which is the better way to get the ip ?

Damien MATHIEU
A: 

On a typical LAN setup, where the entire LAN is connected to the internet via a router, each computer on the LAN would share a "external", WAN IP (assigned to the router), but each of them would have a "internal", LAN IP (typically 192.168..).

In that scenario, all external requests by any computer on that LAN would appear to come from the same WAN IP. The router alone would be aware of which computer on the LAN the request belongs to, so there would be no way for your PHP to detect the LAN IP, but only the WAN IP (via the $_SERVER['REMOTE_ADDR'] element)

If the request is internal (like say to a HTTP server on the same LAN), the $_SERVER['REMOTE_ADDR'] element would retain the LAN IP of the computer that made the request.

In short, the server only knows the IP of the device that sent the request, regardless of whether that IP belongs to a LAN, WAN or any other sort of network.

vaske
A: 

$_SERVER['REMOTE_ADDR'] will give you the IP that the HTTP request was made on. If you are referring to 'user' as the person browsing your website then this is most likely what you are looking for.

If you mean the WAN IP that the 'executing user' has you could use the following line to fetch the WAN IP of your server

$wanIP=file_get_contents("http://www.whatismyip.com/automation/n09230945.asp");

Bear in mind that this will make a DNS and an HTTP connection to whatismyip.com which will slow down your site.

Ben Reisner