I developed a library called PHP-Bouncer that I think would fit your needs very well. It currently supports fully managed access, which will allow you to use one call on each page (I recommend using the cursor, of course), and automatically redirect people if they do not have access to the page, as well as automatically search for roles from the database (if you implement roles in the database using the included MySQL script table setting). The syntax is pretty simple.
You create a bouncer:
$bouncer = new Bouncer();
Add your roles (manually):
// Add a role Name, Array of pages role provides $bouncer->addRole("Public", array("index.php", "about.php", "fail.php")); // Add a role Name, Array of pages role provides $bouncer->addRole("Registered User", array("myaccount.php", "editaccount.php", "viewusers.php")); // Add a role Name, Array of pages role provides List of pages that are overridden by other pages $bouncer->addRole("Admin", array("stats.php", "manageusers.php"), array("viewusers.php" => "manageusers.php"));
or from the database:
// conf_* values are set in a config file, or you can pass them in explicitly $bouncer->readRolesFromDatabase(conf_hostname, conf_username, conf_password, conf_schema, "mysql");
Add a user and give them some roles (Note. There is a BouncerUser class that can extend your user class, it provides all the necessary functionality of a role!):
$user->addRole("Logged In");
Then let Bouncer control access to your files:
$bouncer->manageAccess($user->getRoles(), substr($_SERVER["PHP_SELF"], 1), "fail.php");
If you want to display content on a page only if the user has permission to view, just wrap it:
if($user->hasRole("Registered User")){ echo "The content"; }
I think this would be a great solution for the problem you described!