I'm having a CRAZY session problem which I cannot figure out for the life of me. It's either something I would never have thought of...or it's really simple and I've just been staring at this code for too long to see it. I will be EXTREMELY GRATEFUL for any help.
I have several pages that I have protected by means of PHP session. Each page has the start_session() and then checks to see if the session variable $auth == "yes" (If it's not they are forwarded to the login page).
This is working flawlessly... however... When the user logs in I set several session variables ('auth' being one of them). One of these variables is $ownerID and another is $stype.
Although both session variables are set in the same location with similar code... $stype never gets set (or perhaps can never be recalled). The code follows:
login.php (Where I define the variables)
session_start();
session_register('auth');
session_register('loginname');
session_register('ownerID');
session_register('stype');
session_register('rec2use');
...
login.php (Where I check username and password..and set the variables)
switch (@$do)
{
case "login":
$link = mysql_connect($db_host, $db_user, $db_password)
or die("Could not connect");
mysql_select_db($db_database) or die("Could not select database: $db_database");
$query = "SELECT Username FROM members WHERE Username = '$Username'";
$result = mysql_query($query) or die("Query Failed - line 17");
$num = mysql_num_rows($result);
if ($num == 1) //login name was found in the member directory {
$query2 = "SELECT david_index from `members` WHERE Username='$Username' AND password='$password'";
$result2 = mysql_query($query2) or die("Could not check credentials - Line 22");
$num2 = mysql_num_rows($result2);
if ($num2 > 0) { // password is correct
// ** SET SESSION VARIABLES **
$auth = "yes"; // This works no problem
$a_member = mysql_fetch_row($result2);
$ownerID = $a_member[0]; // This works no problem
$stype = $a_member[18]; // THIS DOES [B]NOT[/B] WORK!
$rec2use = $recnum; // This works no probem
header("Location: $continue");
}
else { // password is NOT correct
// redirect to login failure page
}
}
elseif ($num == 0) { // login name NOT found in the member directory
// redirect to login failure page
}
break;
}
I call these session variables from other pages. 'auth' and 'ownerID' seem to be working fine, but $stype isn't getting (or at least isn't retrieving) a value.
I have inserted test lines such as:
print "Your type is: $a_member[18]";
print "Your stype is: $stype";
above where I set the value and $a_member[18] does indeed have a value here (at the line with the comment '//THIS DOES NOT WORK!'
If anyone has any idea as to why I cannot use $stype, or knows of a better why to work with session variable please let me know.
THANKS in advance for your time/help!
- Dave