Basic Restricted Pages with PHP June 24th, 2014
- Create database with tables (at least 2 with 1 being for users)
- Create a user with limited privledges to the database
- Create a connection file using the new user
- Use the following on the main public page to ensure no sessions are currently active
//CALL SESSION AND DESTROY session_start(); unset($_SESSION); session_destroy();
- Create a loginfailed page
- Create a login page which posts to a login_processor page (can use same code from sample with minor edits for correct variables) and point the form to action=”<?php echo $loginFormAction; ?>”
- On any page you want locked down, call the access script include
- For logout, set any link to href=”<?php echo $logoutAction ?>”>
- Create manage, add, delete, edit, edit_processor, and logout (can use same code from sample with minor edits for correct variables)… be sure to use the following on all restricted pages…
//IF NOT LOGGED IN, GO TO LOGIN session_start(); if (!isset($_SESSION['access'])){ header("Location: login.php"); }