I registered the session, and then I registered the session using the users username.
How then do I retrieve the variable, as it isn't posted on in any way?
<?
$f_user=$_POST['f_user'];
$f_pass=$_POST['f_pass'];
//login.php - performs validation.
//authenticate using form variables
$status = authenticate($f_user, $f_pass);
// if user/pass combination is correct
if ($status == 1)
{
//initiate session
session_start();
//register some session variables
session_register("SESSION");
//including the username
session_register("SESSION_UNAME");
$SESSION_UNAME = $f_user;
//redirect to protected page
header("Location: /secure.php");
exit();
}
else
// user/pass check failed
{
//redirect to error page
header("Location: /secure/error.php?e=$status");
exit();
}
// authenticate username/password against a database
// returns: 0 if username and password is incorrect
// 1 if username and password are correct
function authenticate($user,$pass)
{
$db_host = "localhost";
$db_user = "root";
$db_name = "dbname";
$connection = mysql_connect($db_host, $db_user) or die("unable to connect");
$query="SELECT id from user where user = '$user' and pass = MD5('$pass')";
mysql_select_db($db_name);
$result=mysql_query($query, $connection) or die("error in query: $query. " . mysql_error());
if (mysql_num_rows($result) == 1)
{
return 1;
}
else
{
return0;
}
}
?>
This is the script that checks the users login and password and then if all is correct redirects them to the secure page.
Once on the secure page, how do I then retrieve the username or user details?