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

onurzdgn's avatar

Take customer ip address

Hello everyone. I am using Laravel 10 and Digital Ocean App Platform. I want to take user ip address. After that send ipinfo with api and take customer location and country. I am using $request->ip() however it always return me my server location. How can I fix this problem. I was try $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['HTTP_X_REAL_IP']

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

You behind a proxy?

onurzdgn's avatar

@Snapey Yes I use Cloudflare to and I found https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-connecting-ip I think this is the problem. I will search and write here my solution, if there is no any solution

martinbean's avatar

@onurzdgn If your site is behind a proxy then you need to tell your Laravel application to trust them: https://laravel.com/docs/11.x/requests#configuring-trusted-proxies

Your Laravel app will then correctly determine if it’s running under HTTP or HTTPS, and also the end user’s IP address rather than the IP address of the proxy/load balancer in between your app and the user.

If you’re using Cloudflare, you also don’t need to use “ipinfo” to get the user’s country because Cloudflare will also send that in a CF-IPCountry header: https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#cf-ipcountry

The CF-IPCountry header contains a two-character country code of the originating visitor’s country.

onurzdgn's avatar

@martinbean My problem is my ipinfo link I found it however I am new on cloudflare and digitalocean I am still discovering. Thank you

Please or to participate in this conversation.