Report this

What is the reason for this report?

How to get the true IP of the user with Load Balancer and LAMP?

Posted on June 11, 2019

I’m using Load Balancer and LAMP in my application. But in a feature of my application it is necessary to get the true IP of who is accessing. I tried with PHP in several ways like:

$ _SERVER [‘HTTP_CLIENT_IP’]

$ _SERVER [‘HTTP_X_FORWARDED_FOR’]

$ _SERVER [‘HTTP_X_FORWARDED_FOR’]

But none of these worked, I always get the Load Balancer IP. Can anybody help me?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey there,

You’ll need to enable proxy protocol for the load balancer to forward the client IP.

https://blog.digitalocean.com/load-balancers-now-support-proxy-protocol/ https://www.digitalocean.com/docs/networking/load-balancers/how-to/create/#creating-the-load-balancer

If you continue having issues after enabling proxy protocol for your LB just let me know and I can offer additional advice based on the issue you are facing.

Regards, Ethan Fox Developer Support Engineer II - DigitalOcean

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.