I can not get a variable in a session to unset() and then re-populate and it
is destroyed. Please follow below to get the flow of what I am doing.


I have created a helpdesk application with a login. I am using sessions to
keep track of information I need for the session.
That information is
User's ID
User's Last Name
User's First Name
If the User is Authenticated
and the type user they are.

Here is the page the form goes to after submitting
-------------------------------------------------
<?
if (!$Username || !$Password) { header("Location: error.php?ec=4"); exit; }

   $Now = date("F j, Y, g:i a");
 $IP = GetHostByName($REMOTE_ADDR);
 mysql_connect("localhost", "#######", "###") or die("Could not connect");;
    mysql_select_db("helpdesk");
    $UserResults = mysql_query("SELECT * FROM users WHERE Username =
'$Username' and Password = '$Password'")
  or die("Authentication Database is temporarily offline. Try again
later.<br>");
 $Count = mysql_num_rows($UserResults);
 if($Count == 0) {  header("Location: error.php?ec=1"); exit; }

 // store the details in session variables
 session_start();
 session_register("SESSION");
 session_register("SESSION_FIRSTNAME");
 session_register("SESSION_LASTNAME");
 session_register("SESSION_AUTH");
 session_register("SESSION_USERID");
 session_register("SESSION_USERTYPE");

 // assign values to the session variables
 while ($Users = mysql_fetch_assoc($UserResults)) {
   $SESSION_FIRSTNAME = $Users["FirstName"];
   $SESSION_LASTNAME = $Users["LastName"];
   $SESSION_AUTH = "Yes";
   $SESSION_USERID = $Users["id"];
   $SESSION_USERTYPE = $Users["UserType"];
   }
 // update last login fields and redirect user to the tickets page
    mysql_free_result($UserResults);
    mysql_query("UPDATE users SET LastLoginDate = '$Now', LastLoginIP =
'$IP' WHERE id = '$SESSION_USERID'")
  or die("Authentication Database is temporarily offline. Try again
later.<br>");
    mysql_close();
 header("Location: tickets.php");
?>


When they logout they go to this page;
---------------------------------------------------------
<?php
// logout.php - destroy session

// destroy session variables and send back to login page
session_start();
session_unregister("SESSION");
session_unregister("SESSION_FIRSTNAME");
session_unregister("SESSION_LASTNAME");
session_unregister("SESSION_AUTH");
session_unregister("SESSION_USERID");
session_unregister("SESSION_USERTYPE");
session_unset();
header("Location:index.php");
?>

Here is the problem....
on other pages I am displaying their usertype...

session_start();
if(!session_is_registered("SESSION")) { header("Location: error.php?ec=2");
exit; }
if($SESSION_AUTH != "Yes") { header("Location: error.php?ec=3"); exit; }

HTML <stuff-start>
<?PHP echo $SESSION_USERTYPE; ?>
HTML <stuff-end>

I have two users setup. One has a usertype of "Admin" and the other is
"User". If I login with the admin account, then logout and login with the
user account the variable $SESSION_USERTYPE is always "Admin". Even if I
change it in the database, it never changes. If I go into the database and
change the admin account to "User" it still says Admin. Some where it
appears that the unregister command and even the unset command is not
working. Can anyone tell me what is wrong and more importantly, tell me how
to fix it.




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to