Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hakan's avatar
Level 1

Get Client IP address

Hello! Im a trying to get client IP address but it is returning only my localhost server address(127.0.0.1)

Here is my code:


        public function ip(Request $request)
        {


        $ip=  Request::getClientIp();
        $data = Location::get($ip);
        dd($data,$ip);
        }

I have also tried this one:

        public function ip(Request $request)
        {


        $ip=  \Request::ip();
        $data = Location::get($ip);
        dd($data,$ip);
        }

But im still getting the same result (127.0.0.7) which is my localhost address and not my Ip address.

Please I need help

0 likes
9 replies
zion's avatar

If you are developing and thus connecting local that's the IP you're probably connecting with to your local webserver.

hakan's avatar
Level 1

Yes Im developing! But How could i know that if it could return a user or client ip?

hakan's avatar
Level 1

The thing is that I want to get Client Public IP!

Thyrosis's avatar
Thyrosis
Best Answer
Level 17

It will get the client public IP. Run it on a live server and see the results. You'll see your own public IP pop up.

hakan's avatar
Level 1

Thank you for answering back! Im going to check and see

inmn's avatar

Lol. Your IP is 127 because youre local server is 127.

If you want to see your ISP's IP, you have to actually use it to connect to your local server

(public SHARE is another option.. etc)

1 like
hakan's avatar
Level 1

Thank you so much! for answering me back!

Sinnbeck's avatar

@yomi Please dont revive 5 year old threads. And yes (but the syntax has changed. Check the docs)

2 likes

Please or to participate in this conversation.