Hai Guys, How to get wan ip address of my user using php....
I found the best option is using the latest WhatIsMyIPAddress API, http://bot.whatismyipaddress.com, and usage is recommended to 1 query per 5 minutes [Source]. It returns the WAN IP in plaintext so using
file_get_contents("http://bot.whatismyipaddress.com");
will get the IP easily without any post-parsing necessary.
$_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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With