slj90 Posted January 18, 2010 Share Posted January 18, 2010 I currently have a code to see if the user is logged in, <? // Check if we have an authenticated user if (!isset($_SESSION["authenticatedUser"])) //if not re-direct to login page { $_SESSION["message"] = "Please Login"; header("Location: loginpage.php"); } else; { //If authenticated then display page conetents ?> How can I change it for my admin page, so if the users username (authenticatedUser) isn't 'Admin' it tkaes them back to the login? Thank you Link to comment https://forums.phpfreaks.com/topic/188868-if-user-not-admin-redirect/ Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 <?php session_start(); // Check if we have an authenticated user if (isset($_SESSION['authenticatedUser']) && $_SESSION["authenticatedUser"] != 'admin') { //If user is not admin, but accessing admin page: $_SESSION["message"] = "You do not have access to this page"; header("Location: home.php"); //or wherever } else { echo 'Welcome Admin!'; } ?> EDIT: Fixed your code up a little. Link to comment https://forums.phpfreaks.com/topic/188868-if-user-not-admin-redirect/#findComment-997152 Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 // Check if we have an authenticated user if (!isset($_SESSION["authenticatedUser"]) || (isset($_SESSION['authenticatedUser']) && $_SESSION['authenticatedUser'] != 'admin')) { $_SESSION["message"] = "Please Login"; header("Location: loginpage.php"); } else { // display page contents // } Might do the trick.. Link to comment https://forums.phpfreaks.com/topic/188868-if-user-not-admin-redirect/#findComment-997154 Share on other sites More sharing options...
slj90 Posted January 18, 2010 Author Share Posted January 18, 2010 Thankyou, it is working great Link to comment https://forums.phpfreaks.com/topic/188868-if-user-not-admin-redirect/#findComment-997182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.