I am connected to a lan.. I can access internet. using the browser I can find my public ip using the search "what is my ip".
I want to get the public ip using php
I am running the script in my localhost
wamp server..
I tried:
$_SERVER['REMOTE_ADDR'] and $_SERVER['SERVER_ADDR']` both give me `localhost ip ::1
Is there any networking functions that can give me my public ip address?
is there any way without using any external service? because if I use an external service, it may not available in the future.
try this please:
$externalContent = file_get_contents('http://checkip.dyndns.com/');
preg_match('/Current IP Address: \[?([:.0-9a-fA-F]+)\]?/', $externalContent, $m);
$externalIp = $m[1];
Or use httpbin.org/ip as Priyesh Kumar suggests
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