Jump to content

Session variables no holding values


jim.davidson

Recommended Posts

I'm having a problem with session variable retaining updated values. Here's what I'm doing

 

member_login.php

<?php require_once('Connections/rclub.php'); ?>

<?php

session_start();

$_SESSION['MM_Username'] = 'X';

$_SESSION['MM_UserGroup'] = 0;

$_SESSION['user_name'] = 'j';

$_SESSION['Logged_in'] = 'no';

$_SESSION['MM_user_level'] = 0;

 

if (isset($_POST['username'])) {

$loginUsername=trim($_POST['username']);

$password=$_POST['password'];

$MM_fldUserAuthorization = "user_level";

$MM_redirectLoginSuccess = "login_passed.php";

$MM_redirectLoginFailed = "login_failed.php";

$MM_redirecttoReferrer = false;

mysql_select_db($database_rclub, $rclub);

$LoginRS__query=sprintf("SELECT username, password, user_level, user_id, first_name, last_name, member_id FROM users WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $rclub) or die(mysql_error());

$loginFoundUser = mysql_num_rows($LoginRS);

$row_loginFoundUser = mysql_fetch_assoc($LoginRS);

// echo $loginFoundUser;

if ($loginFoundUser) {

$loginStrGroup = mysql_result($LoginRS,0,'user_level');

$loginMemberId = mysql_result($LoginRS,0,'member_id');

//declare two session variables and assign them

$_SESSION['MM_Username'] = $loginUsername;

$_SESSION['MM_UserGroup'] = $loginStrGroup;

$_SESSION['MM_user_level'] = $loginStrGroup;

$_SESSION['member_id'] = $loginMemberId;

$_SESSION['user_id'] = $row_loginFoundUser['user_id'];

$f_name = $row_loginFoundUser['first_name'];

$l_name = $row_loginFoundUser['last_name'];

$fullname = trim($f_name);

$fullname .= ' ';

$fullname .= trim($l_name);

$_SESSION['user_name'] = $fullname;

echo $_SESSION['MM_Username'];

echo $_SESSION['MM_UserGroup'];

echo $_SESSION['user_name'];

echo $_SESSION['user_id'];

header("Location: " . $MM_redirectLoginSuccess );

}

else {

header("Location: ". $MM_redirectLoginFailed );

}

}

 

echo results are:

$_SESSION['MM_Username'] = jim.davidson

$_SESSION['MM_UserGroup'] = 1

$_SESSION['user_name'] = Jim Davidson

$_SESSION['user_id'] = 1

So the session variables have been updated. I then go back,comment out the echos (otherwise get headers sent error) enter the same data and now goes to login_passed.php.

 

login_passed.php

<?php

//initialize the session

if (!isset($_SESSION)) {

session_start();

}

?>

<?php require_once('Connections/rclub.php'); ?>

<?php

Here I echo the session variables

echo $_SESSION['MM_Username'];

echo $_SESSION['MM_UserGroup'];

echo $_SESSION['user_name'];

echo $_SESSION['user_id'];

echo results are:

$_SESSION['MM_Username'] = X

$_SESSION['MM_UserGroup'] = 0

$_SESSION['user_name'] = j

$_SESSION['user_id'] = nothing

Three of the session variable reverted back to their original state and the fourth one is empty. Anyone have an idea as to why session varibles are notshowing the updated state?

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.