Hi, i’ve been working on a project’s website and want to make a website. I need a page for the team. and i want to make the non-whitelisted people redirect to the home page. any help?
First, create an array of the IPs:
$ips = array("1.1.1.1", "1.1.1.2");
Then, detect if one of them visited the page:
if(in_array($_SERVER['REMOTE_ADDR'], $ips)
{
// Code to run if admin
}
2 Likes
Great solution. If I may make one suggestion to tidy the potential code of the page…
instead of nesting everything an authorised user can do within the if
, just kick all unauthorised users with a 401, then you can have your page code outside the if
block:
if(!in_array($_SERVER['REMOTE_ADDR'], $ips))
{
header("HTTP/1.1 401 Unauthorized");
exit;
}
// Page code for authorised users
(Notice the not, !
, in the if-statement)
But all credit to Riverside for doing the legwork…
3 Likes
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.