Forums
This topic is locked
session variable
Posted 13 Feb 2005 17:23:02
1
has voted
13 Feb 2005 17:23:02 walter napoleon posted:
1) I have a login page which writes username and password into a database. After login the server behavior swiches to a login_ok.php or a login_fail.php. Thusfar every works fine. But in the login_ok I want to use the session variable MM_username created by the login page. In the datababindings panel I created a session variable MM_username and dragt it into the page. This won't work. What do I do wrong?It seems the loging page doesn't generate the session variable MM_Username. I have even tried by defining in the login.php page a recordset using the session variable MM_Username. It does not help.
2) How can I use the session variable MM_UserGroup to display the access level of the user?
This my login page (I ommitted the php tags):
php require_once('Connections/conn_Dmenu.php');
mysql_select_db($database_conn_Dmenu, $conn_Dmenu);
$query_rstUsers = "SELECT * FROM tblUsers";
$rstUsers = mysql_query($query_rstUsers, $conn_Dmenu) or die(mysql_error());
$row_rstUsers = mysql_fetch_assoc($rstUsers);
$totalRows_rstUsers = mysql_num_rows($rstUsers);
// *** Validate request to login to this site.
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}
if (isset($_POST['Username'])) {
$loginUsername=$_POST['Username'];
$password=$_POST['UserPw'];
$MM_fldUserAuthorization = "UserStatus";
$MM_redirectLoginSuccess = "login_ok.php";
$MM_redirectLoginFailed = "login_fail.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_conn_Dmenu, $conn_Dmenu);
$LoginRS__query=sprintf("SELECT UserName, UserPw, UserStatus FROM tblUsers WHERE UserName='%s' AND UserPw='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
$LoginRS = mysql_query($LoginRS__query, $conn_Dmenu) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'UserStatus');
//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;
//register the session variables
session_register("MM_Username"

session_register("MM_UserGroup"

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
*************************************************************
This is my login_ok page:
You are loged in as : php echo $_SESSION['MM_username']; </p>
<p>Your status is : </p>
<p><a href="index.php">Back to homepage</a> </p>
Replies
Replied 14 Feb 2005 10:33:21
14 Feb 2005 10:33:21 Vince Baker replied:
Hi Walter,
Please do not post the same topic in more than one forum.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Please do not post the same topic in more than one forum.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]