Jump to content


Photo

User login - problems with sessions


  • Please log in to reply
2 replies to this topic

#1 luth116

luth116
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 September 2004 - 10:44 PM

I have problems with sessions. It looks like the session variable "MM_UserID" is not passing from one page to another. I created a login page (login.php) and built the form and added dreamweaver mx's login behavior to it.I then created a user info page (login_success.php) which users reach right after logging in that displays several bits of information from their entry in the database table. When I login, the login is successful but no dynamic data (the user's info) is displayed on the user info page. The codes for both the login page and the userinfo page are below:

login.php

<?php

//initialize the session
session_start();

include '../Connections/mcssb.php';

// *** Validate request to login to this site.

if (isset($_POST['Login'])) {
if (isset($_POST['StoreProfile'])) {
setcookie ("UserName", $_POST['UserName'],time()+43200);
} else {
setcookie ("UserName", "",time()-43200);
}
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$_SESSION['PrevUrl'] = $accesscheck;
}

if (isset($_POST['UserName'])) {
$loginUsername=$_POST['UserName'];
$password=$_POST['Password'];
$MM_fldUserAuthorization = "UserAccess";
$MM_redirectLoginSuccess = "login_success.php";
$MM_redirectLoginFailed = "login.php?failed=true";
$MM_redirecttoReferrer = true;
mysql_select_db($database_mcssb, $mcssb);

$LoginRS__query=sprintf("SELECT UserName, UserPassword, UserAccess, UserID FROM users WHERE UserName='%s' AND UserPassword='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $mcssb) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {

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

//register the session variables
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserID'] = mysql_result($LoginRS,0,'UserID');
$_SESSION['MM_UserGroup'] = $loginStrGroup;

if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: http://${_SERVER['HTTP_HOST']}/" . dirname($_SERVER['PHP_SELF']) . "/$MM_redirectLoginSuccess?" . SID);
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

login_success.php

<?php //initialize the session
session_start();

include '../Connections/mcssb.php';

$colname_LoggedIn = "1";
if (isset($_SESSION['MM_UserID'])) {
$colname_LoggedIn = (get_magic_quotes_gpc()) ? $_SESSION['MM_UserID'] : addslashes($_SESSION['MM_UserID']);
}
mysql_select_db($database_mcssb, $mcssb);
$query_LoggedIn = sprintf("SELECT UserID, UserName, UserEmail FROM users WHERE UserID = %s", $colname_LoggedIn);
$LoggedIn = mysql_query($query_LoggedIn, $mcssb) or die(mysql_error());
$row_LoggedIn = mysql_fetch_assoc($LoggedIn);
$totalRows_LoggedIn = mysql_num_rows($LoggedIn);
?>


#2 morpheus.100

morpheus.100
  • Members
  • PipPipPip
  • Advanced Member
  • 145 posts

Posted 15 September 2004 - 10:18 PM

I assume you are testing with IE 6

Replace
//initialize the session
session_start();

with

//initialize the session
session_start();
header(Cache-control:private); //ie fix

#3 luth116

luth116
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 October 2004 - 04:20 PM

Correcting the cache-control in the header as mentioned above doesn’t always work. The following worked for me, by placing a session_write_close() before the call to header, followed by and exit():

session_write_close();
header("Location: $Page");
exit();

More about the same:

After you install security patch MS01-055 for Microsoft Internet Explorer 5.5 or 6.0, you may encounter the following problems:
-Session variables are lost.
-Session state is not maintained between requests.
-Cookies are not set on the client system.

http://support.micro...kb;EN-US;316112




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users