Hi all,
Having a problem registering sessions.
The login code works fine but when I go to another page after logging in the session does not exist.
Why is this??
Used this in both pages:
<?php
session_start();
?>
Login Code:
$query = "select * from admin where username = '$username'
and password = '$password'" or die(mysql_error());
$result = mysql_query($query);
if (mysql_num_rows($result)>0)
{
// if they are in the database register the user id
$HTTP_SESSION_VARS['valid_user'] = $username;
}
else {
echo '<p>Unable to log in<br /><br />';
echo '<a href="#" onClick="history.go(-1)">Go Back</a></p>';
}
// Check if registered session variable
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo '<p>You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].'<br /><br />';
echo '<a href="../one.php">M-Lists</a><br /><br />';
echo '<a href="logout.php">Logout</a></p><br />';
}
else
{
if (isset ($username))
{
// if they tried and failed to log in
echo '<p>Could not log you in</p>';
}
}
?>