crjunk crjunk - 1 year ago 65
PHP Question

Redirect User if Internal IP Address

I am not familiar with PHP but I need to create a simple page to temporarily redirect internal users until a production problem is fixed.

If the user's IP address starts with

, or
then I need to redirect them to another server. If the user's IP address does not meet this criteria then I need to display a message telling the user the site is down for maintenance.

Can someone help me with this?

Answer Source
$chunks = explode('.', $_SERVER['REMOTE_ADDR']);
$whitelist = array(10, 192, 172);
$server = "";
if(in_array($chunks[0], $whitelist))
    //redirect to another server
    header("Location: " . $server);
    //Show maintenance message
    die("The site is down for maintenance.");