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

Ligonsker's avatar

Does the request's ip() method still return the Load Balancer ip address if the app is behind one?

Hello,

I found a post on Stack Overflow where someone asked how to get the ip address of the client. Then someone mentioned that the request's ip() method will return the Load Balancer IP if it exists: https://stackoverflow.com/a/41769505/17746636

And created a method that works around that.

Is this still relevant? Or it's been fixed already and I will actually get the real client IP?

Thanks

0 likes
2 replies
tisuchi's avatar

@ligonsker Does it works if you set:

protected $proxies = '*';

protected $headers = Request::HEADER_X_FORWARDED_ALL;

In your app/Http/Middleware/TrustProxies.php.

1 like
Ligonsker's avatar

@tisuchi it works even now, but just wanted to know how reliable it is and if I should already use the modified method from the post but looks like it was fixed

1 like

Please or to participate in this conversation.