You can get the client real IP in PHP applications using following code: Laravel provides a convenient way to retrieve client IP: But they are not working when your website is behind the Cloudflare or other proxies (e.g. a load balancer) and all return the Cloudflare Server IP. However, there is a method in symfony/httpfoundation.php to bypass the proxy server IP. So, we can call this method in AppServiceProvider like this: After adding the above will result to return the real client IP from request()->ip & requset()->getClientIp() . Consider you can pass the static IPs as first parameter to setTrustedProxies and works fine for proxy servers with fixed IP address. However, the Cloudflare changes the server and IP address and it is highly recommended to use ['REMOTE_ADDR'] as first parameter.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners