NathanLedet Posted July 20, 2008 Share Posted July 20, 2008 I have inside a database with a column called isAdmin with a 1 or 0. 1 means they are an Admin and 0 means they are not. When they log in, I store a session, $_SESSION['isAdmin'] which returns a 1 or a 0 Now, when i go to a specific page, I have this script that's not working properly: session_start(); if ($_SESSION['isAdmin'] == 1){ echo "isAdmin is 1<br />"; //Admin options go here } When I'm logged out, and I go to the page, it seems to ignore the check to see if the session is 1 and displays the "isAdmin is 1" string. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 can we see your logout function??? Quote Link to comment Share on other sites More sharing options...
NathanLedet Posted July 20, 2008 Author Share Posted July 20, 2008 can we see your logout function??? silly me. That reminded me to unset the session! What's in bold is what I just added...I will test and ensure that was my issue, and will respond to let you know that was the issue. Thanks! if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles $_SESSION['MM_Username'] = NULL; $_SESSION['MM_UserGroup'] = NULL; $_SESSION['PrevUrl'] = NULL; $_SESSION['isAdmin'] = NULL; unset($_SESSION['MM_Username']); unset($_SESSION['MM_UserGroup']); unset($_SESSION['PrevUrl']); unset($_SESSION['isAdmin']); $logoutGoTo = "index.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } Quote Link to comment Share on other sites More sharing options...
NathanLedet Posted July 20, 2008 Author Share Posted July 20, 2008 Indeed that was it. Thanks! *solved* Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 20, 2008 Share Posted July 20, 2008 Just a suggestion for better buidling using sessions is to always define arrays in you session variables that pretain to what those variables are about For example if you are storing User Login Data, Shopping Cart data and Site vars all in sessions you should organize your sessions vars to be like <?php $_SESSION['UserData']['UserID'] = "1"; $_SESSION['UserData']['Is_Admin'] = "1"; $_SESSION["UserData']['Username'] = "Joebob"; $_SESSION['CartData']['CartID'] = "654234"; $_SESSION['CartData']['CartName'] = "Cart 1"; $_SESSION["SiteVars']['Lang'] = "English"; $_SESSION['SiteVars']['Resolution'] = "800*600"; ?> then if a user logs out you simply can delete all the user data sessions by saying <?php $_SESSION['UserData'] = array(); ?> Or to delete the shopping cart <?php $_SESSION['CartData'] = array(); ?> I don't like to muddy my global level of my sessions because I've sometimes like to use the same name for session data pertaining to two different things and you don't realize you have problems later. Quote Link to comment Share on other sites More sharing options...
NathanLedet Posted July 20, 2008 Author Share Posted July 20, 2008 Great tip! I appreciate it and will make a note of it Quote Link to comment 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.