Cannot pass value of Session("MM_username")
I am working in PHP and havev built a basic Log in page which contains a form for the user to enter Username and Password. Using the Server Behavior "log in User" it is supose to validate these two fields against a PHP MYSQL database. After enter the form data and submitting it the correct behaviors thus validating the data. When I pass it to another page to call the full record data using the two entered fields it does not work. I have spent hours debugging and from what I can see is the Session variable MM_username is not getting set. Below is the code for the entry form:
Login_test.php
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "test_username.php";
$MM_redirectLoginFailed = "unauthorize.html";
$MM_redirecttoReferrer = false;
mysql_select_db($database_localhost, $localhost);
$LoginRS__query=sprintf("SELECT user_name, password FROM user_info WHERE user_name=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<form ACTION="<?php echo $loginFormAction; ?>" id="form1" name="form1" method="POST">
<table width="50%" border="0">
<tbody>
<tr>
<th width="48%" align="right" scope="row">User Name:</th>
<td width="52%"><input type="text" name="username" id="username"></td>
</tr>
<tr>
<th align="right" scope="row">Password:</th>
<td><input type="text" name="password" id="password"></td>
</tr>
<tr>
<th align="right" scope="row"> </th>
<td> </td>
</tr>
<tr>
<th align="right" scope="row"> </th>
<td><input type="submit" name="submit" id="submit" value="Login"></td>
</tr>
<tr>
<th align="right" scope="row"><a href="registration.php">Create New Account</a></th>
<td> </td>
</tr>
</tbody>
</table>
<p> </p>
</form>
</body>
</html>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
if (isset($_SESSION['MM_username'])) {
$colname_Recordset1 = $_SESSION['MM_username'];
}
mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = sprintf("SELECT * FROM user_info WHERE user_name = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<html>
<?php require "header.php"; ?>
<?php
mysql_free_result($Recordset1);
?>
<!doctype html>
<head></head>
<body>
<?php
if (isset($_SESSION["MM_username"])) {
$loggenOnUser = $_SESSION["MM_username"];
echo "Found User: ", $loggenOnUser, "<br />";
} else {
$loggenOnUser = " a public user";
}
?>
<div class="gridContainer clearfix">
<div id="div1" class="fluid">
This page is being called by my login.php file.
</div>
<div id="LoggedInUser" class="fluid ">
Hi. I'm <?php echo $loggenOnUser; ?>
</div>
<img id="homeImage" src="images/home.gif" /> </div>
</div>
</body>
</html>
