Skip to content

Instantly share code, notes, and snippets.

@gabrielef
Last active December 22, 2015 06:58
Show Gist options
  • Save gabrielef/6434583 to your computer and use it in GitHub Desktop.
Save gabrielef/6434583 to your computer and use it in GitHub Desktop.
Thi script redirect not unauthorized users, for example during maintenance.Put ip address of authorized users inside the $admin array.
<?php
//admins address
$admins = array('97.23.95.1', '192.168.1.74');
//redirect page for unauthorized users
$page = 'http://www.sitename.com/redirectpage.html';
//////////////////////////////////////////////////////////////////////////
//user ip address
$user = $_SERVER['REMOTE_ADDR'];
//user will be redirect to $page if its ip isn't in the $admin array
//var_dump(array_search($user, $admin));
if(array_search($user, $admins) === FALSE)
{
header('Location: ' . $page);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment