Session not registered?
Posted: Sat Oct 01, 2005 2:09 am
This short test.php is to give a login acess. Once logged in, errMsg shows SECCESS and the session MM_Username will be shown; a FAILED is shown if it's given wrong login info. All code is created by Dreamweaver 2004 MX and I didn't modify any code inside.
Now I start to test it. I input a pair of username and password which is loaded in the database before. Enter. errMsg shows SECCESS but the value of session MM_Username never ever shows up. What can I do? (I tested to input incorrect username and/or password, errMsg did show FAILED when there were wrong. So the database connection should probabiy be no problem.)
Thank you
Now I start to test it. I input a pair of username and password which is loaded in the database before. Enter. errMsg shows SECCESS but the value of session MM_Username never ever shows up. What can I do? (I tested to input incorrect username and/or password, errMsg did show FAILED when there were wrong. So the database connection should probabiy be no problem.)
Thank you
Code: Select all
<?php require_once('../Connections/IBGY.php'); ?>
<?php
// *** Start the session
session_start();
// *** Validate request to log in to this site.
$FF_LoginAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING']) && $HTTP_SERVER_VARS['QUERY_STRING']!="") $FF_LoginAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
if (isset($HTTP_POST_VARS['textfield1'])) {
$FF_valUsername=$HTTP_POST_VARS['textfield1'];
$FF_valPassword=$HTTP_POST_VARS['textfield2'];
$FF_fldUserAuthorization="";
$FF_redirectLoginSuccess="test.php?errMsg=Success";
$FF_redirectLoginFailed="test.php?errMsg=Failed";
$FF_rsUser_Source="SELECT lg_username, lg_password ";
if ($FF_fldUserAuthorization != "") $FF_rsUser_Source .= "," . $FF_fldUserAuthorization;
$FF_rsUser_Source .= " FROM logon WHERE lg_username='" . $FF_valUsername . "' AND lg_password='" . $FF_valPassword . "'";
mysql_select_db($database_IBGY, $IBGY);
$FF_rsUser=mysql_query($FF_rsUser_Source, $IBGY) or die(mysql_error());
$row_FF_rsUser = mysql_fetch_assoc($FF_rsUser);
if(mysql_num_rows($FF_rsUser) > 0) {
// username and password match - this is a valid user
$MM_Username=$FF_valUsername;
session_register("MM_Username");
if ($FF_fldUserAuthorization != "") {
$MM_UserAuthorization=$row_FF_rsUser[$FF_fldUserAuthorization];
} else {
$MM_UserAuthorization="";
}
session_register("MM_UserAuthorization");
if (isset($accessdenied) && false) {
$FF_redirectLoginSuccess = $accessdenied;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = false;
header ("Location: $FF_redirectLoginSuccess");
exit;
}
mysql_free_result($FF_rsUser);
session_register("FF_login_failed");
$FF_login_failed = true;
header ("Location: $FF_redirectLoginFailed");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEST</title>
</head>
<body>
<form name="form1" method="POST" action="<?php echo $FF_LoginAction?>">
username:
<input name="textfield1" type="text" id="textfield1">
Password:
<input name="textfield2" type="text" id="textfield2">
<input type="submit" name="Submit" value="Login">
<?php echo $_GET['errMsg']; ?>
</form>
<?php echo $_SESSION['MM_Username']; ?>
</body>
</html>