This question already has an answer here:
I am told that I should use filter_input rather than accessing $_SERVER directly
So I made this simple 2 line of code
echo "filter:input " . filter_input(INPUT_SERVER,'REMOTE_ADDR');
echo "SERVER:" .$_SERVER['REMOTE_ADDR'] ;
Very simple. I expect they both produce the exact same thing.
This is what I got
filter:input SERVER:202.80.212.17
Clearly filter_input(INPUT_SERVER,'REMOTE_ADDR') produces empty string.
Why?
</div>
It has been a bug in older versions of php. You can either use
echo "filter:input " . filter_input(INPUT_ENV, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
Or use
echo "filter:input " . filter_input($_SERVER['REMOTE_ADDR']);