how to get public ip address of my localhost system

Viewed 3038

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.

5 Answers

Try this as it is tested on local machine(localhost)

$ip = file_get_contents('https://api.ipify.org'); echo $ip;

Related