Iman Sedighi
Iman Sedighi

Reputation: 8192

Amazon EC2 web server shows an incorrect client IP in PHP

I have one load balancer and three EC2 web servers with Linux and Apache. Whenever I use $_SERVER['REMOTE_ADDR'] in PHP to take website's visitor's IP addresses, It shows me a wrong IP address. When I check the IP in Whois databases then I will find its a reserved IP. I guess its IP of another server in AWS itself instead of client's IP. How Can I get correct client's IP with PHP in EC2 servers?

Upvotes: 1

Views: 1525

Answers (1)

Shutterfly
Shutterfly

Reputation: 199

The IP is a local Amazon IP because the visitors does not connect to your server directly.

Normally the Load balancer forwards the real client IP in the $_SERVER array under a new key, in most cases $_SERVER['HTTP_X_FORWARDED_FOR']

Upvotes: 6

Related Questions