Jump to content

[SOLVED] Sessions problem


NathanLedet

Recommended Posts

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.

Link to comment
Share on other sites

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;

  }

}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.