Luke
Luke

Reputation: 21286

PHP $_SERVER['REMOTE_ADDR'] sometimes resolves to empty string

When accessing my site from a number of machines $_SERVER['REMOTE_ADDR'] always resolves to an empty string. What can be the cause of this?

Additional info: One of the machines is running the site on localhost. Shouldn't a machine on localhost always resolve to 127.0.0.1?

My set up is LAMP. One dev. machine that runs the site localhost and that has the problem is a Mac and runs XAMPP. I think our live staging environment is CentOS (shared host).

Upvotes: 3

Views: 1800

Answers (3)

Per Johansson
Per Johansson

Reputation: 6887

I just ran into this problem, and it turns out that the PHP code was setting it to '' explicitly before running my code. This was because the IPv6 remote addr didn't match its IPv4 only regex.

Leaving this here in case someone else has the same problem, it was a too simple reason for me to spot it.

The module in question was simplemachinesforum.

Upvotes: 1

Ólafur Waage
Ólafur Waage

Reputation: 70011

Try looking at phpinfo() from those machines and see what they present.

Upvotes: 0

Jan Jungnickel
Jan Jungnickel

Reputation: 2114

I guess this results from a missing reverse delegation for the address. You should avoid reverse resolution unless absolutely necessary.

Not only is it expensive in terms of latency, but can also yield unexpected results as there is no requirement on what to resolve to - or to resolve at aall.

Upvotes: 2

Related Questions