One of these days I will get out of the Newbies Forum. 🙂
I have a login page and when I go to this page from another page, I save the HTTP_REFERER variable so I know where I came from. This works as long as I login correctly. However, if I don't login correctly, I am sent back to the login page, and then my HTTP_REFERER become the login page and so no matter what I do now, I am always sent to the login page.
I am wondering the best approach to resolve this. Below, I have my Login Action code where I handle the login.
session_start();
require_once('Connections/Holocron.php');
$referer = $_SERVER['HTTP_REFERER'];
$user = $_POST['username'];
$password = $_POST['password'];
mysql_select_db($database_Holocron, $Holocron);
$query = mysql_query("SELECT * FROM users WHERE Username = '$user'");
$data = mysql_fetch_object($query);
$stored_pass = $data->Password;
if ($stored_pass == $password)
{
$query2 = mysql_query("SELECT rolename FROM user_roles WHERE Username = '$user'");
$data2 = mysql_fetch_object($query2);
$_SESSION['loggedin'] = 1;
$_SESSION['user'] = $data->Username;
$_SESSION['role'] = $data2->rolename;
echo $referer . "<BR>";
echo "Logging you in $user with role $data2->rolename. Please wait...";
echo "<meta http-equiv='refresh' content='3;URL=" . $referer . "'>";
}
else
{
Header("Location:LoginForm.php?failed=true");
}
Thanks.
Gregg