Background: Password controlled areas of the website using Sessions. Login info is saved in Session variables to control access and each page checks to see if user is logged in.
My Problem: Allow Admins seamless access into certain areas of
the website without re-designing the existing user d-base.
First Answer: Without knowing every aspect of PHP and knowing something about a few other languages my first answer was to use an unless() function to say that "unless the user is an admin, don't let them see this page".
Next Problem: PHP doesn't have an Unless() function...
Answer:
AdminCheck.php
<?
if ($_SESSION[login]!="Admin1" && $_SESSION[login]!="Admin2"){
print "You are not authorized to access this area of the site.";
exit;
}
?>
I use this as an included page at the top of pages that only Admins should have access to. The rest of the page looks normal and is unimpeded by a page long if() loop granting access to the page inside a monster code block. (One of the pages I'm now using this on is over 1000+ lines of code).
The answer seems simple enough... even laughable... but wanting to use an unless() function I got tripped up. I almost considered learning how to contribute to PHP to add this function (like I need another project right now). Maybe someday I will write an unless() function for PHP, but it's not neccessary for now...I hope someone finds this useful.