Load Balancer $_SERVER[‘REMOTE_ADDR’] Not working

Question:

I’ve switched to using an Amazon AWS Elastic Load Balancer and now I’m getting a private IP address for $_SERVER['REMOTE_ADDR'] – which used to give me the client’s IP address.

How do I get the clients IP address now?

Answer:

Your webserver receives HTTP requests from the Amazon ELB. Therefore, the remote address will always be one of the ELB ip addresses.
If you need the remote host’s address from behind the ELB, get it from HTTP header “X-Forwarded-For”.

Leave a Reply