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 Quote 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. Quote 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.. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.