I have generally assumed that in a PHP script I can test $_SERVER['REMOTE_ADDR']
to establish the IP address from which the request originated. However, I am starting to wonder if things are not a bit more complicated. Here is the scenario
- I run a number of servers, call them A, B and C - on which users have to be "registered"
- I run a separate registration server, call it S, where the users' credentials etc are first verified prior to sending out a complete registration request to servers A, B and C
The request goes out as
file_get_contents('https://url?data=value')
On servers A, B and C I was quite naively testing $_SERVER['REMOTE_ADDR']
to establish that the request was in fact coming from server S. Much to my surprise the results turned out to be patchy and variable
- The value in
REMOTE_ADDR
was the IP address of the human user interacting with the registration server, S - The value in
REMOTE_ADDR
was the IP address of the registration server, S - what I had expected to see all the time - The value in
REMOTE_ADDR
was another IP address from the pool of IP addresses on the virtual server where I host server S
I don't really need to perform this additional verification test so I can drop it out altogether. Nevertheless this result has taken me by surprise so I am curious to see if someone here can shed some light on what is going on.
I should mention that I am running PHP 5.5 on Lighttpd on servers A, B and C and PHP 5.3 on Apache 2 on server S.
module
orfcgi/fpm
? Please check also the variables$_SERVER['HTTP_CLIENT_IP']
and$_SERVER['HTTP_X_FORWARDED_FOR']
, as all of the three variables are differently populated when using different servers, (reverse)proxies and configuration. – Friedcake$_SERVER['REMOTE_ADDR']
is the public IP address to directly respond to - it's not possible to fake it (unless the attacker doesn't care to receive the response). From what's in the question: there are flaws in how you're testing, as that's not how it works. – RaincoatREMOTE_ADDR
. – Friedcakefile_get_contents('http://google.com');
and google to see my public IP (or that of my router, or that of my proxy, or that of my firewall etc.)? – Raincoatfile_get_contents('http://example.com');
passing the end-clients IP I'd like to see it. – RaincoatREMOTE_ADDR
can also contain a list of IP numbers, or even"unknown"
. – Shenitashenk