Skip to content
Advertisement

How to get client IP address in Laravel 5+

I am trying to get the client’s IP address in Laravel.

It is easy to get a client’s IP in PHP by using $_SERVER["REMOTE_ADDR"]. It is working fine in core PHP, but when I use the same thing in Laravel, it returns the server IP instead of the visitor’s IP.

Advertisement

Answer

Looking at the Laravel API:

JavaScript

Internally, it uses the getClientIps method from the Symfony Request Object:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement