Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get wan ip address using php [closed]

Tags:

php

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

like image 747
ACP Avatar asked Nov 25 '25 09:11

ACP


2 Answers

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.

like image 99
Hamman Samuel Avatar answered Nov 26 '25 23:11

Hamman Samuel


$_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.

like image 34
Ben Reisner Avatar answered Nov 26 '25 22:11

Ben Reisner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!