Julian Julian - 1 month ago 21
PHP Question

Bypass on specific ip

I am using this code and my question is: how to bypass this on a specific IP:

// Maintenance
$maintenance = 0;if($maintenance): // 0 = no maintenance, 1 = maintenance
require_once($_SERVER["DOCUMENT_ROOT"] . "/maintenance.php");
exit();
endif;


Thanks

Answer

You can use REMOTE_ADDR of the $_SERVER environment variable to achieve this.

if ( $_SERVER['REMOTE_ADDR'] != "xxx.xxx.xxx.xxx" && $maintenance )
{
    //Display Maintenance Page
    die(include('maintenance.php'));
}

    //Normal stuff

However, if the user is behind a proxy, or if there is a WAF between you and the Apache/ngix/etc server, you might have to use the 'HTTP_X_FORWARDED_FOR' variable instead, that is if the proxy/WAF applies that header.

Comments