I have the following code to display secret content on a publically accessible webpage. This secret content is to only be seen by people 'sitting behind' 1-3 specific IP addresses. I've had a go with the code below using just $_SERVER['REMOTE_ADDR']
and it works, I've previously read that people also use: HTTP_X_FORWARDED etc, and that:
If relying on IP addresses for something mission critical, resort to REMOTE_ADDR and don't bother catering to those behind a proxy.
Is it secure to just use $_SERVER['REMOTE_ADDR'] to display 'secret content' based on IP address?
$allowed_ips = array(
'111.222.333.444',
'555.666.777.888',
'999.111.222.333'
);
if (in_array($_SERVER['REMOTE_ADDR'], $allowed_ips))
{
echo 'this is secret stuff only for certain IPs';
}