Login Redirection
Posted: Thu Jan 29, 2004 1:32 pm
I am trying to write a script so that after a person logs on, it takes them back to the URL they were before they logged on. The only problem is, it doesn't seem to work at all. It allows users to login, but takes them straight back to index.php. Here is the code for the Login form
and here is the script that allows members to log in
Code: Select all
<?php
include('banned.php');
include('start.php');
?>
<BODY bgcolor="#000000" text="#FFFFFF" link="#0000FF" vlink="#0000FF" alink="#0000FF">
<form action="login.php" method="post">
<?php
if (isset($_SERVER['HTTP_REFERER'])) {
$referer = parse_url($_SERVER['HTTP_REFERER']);
?>
<input type="hidden" name="redir" value="<?php echo $referer; ?>">
<?php
} else {
?>
<input type="hidden" name="redir" value="index.php">
<?php
}
?>
Username
<input type="text" name="username"><br>
Password
<input type="password" name="password"><br>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Reset">
<?php
include('end.php');
?>Code: Select all
<?php
include('banned.php');
if ( isset($_POST['username']) and isset($_POST['password']) and isset($_POST['redir']) ) {
$username = strtolower($_POST['username']);
$password = $_POST['password'];
$dbname = 'eckbios';
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){
$sql = "SELECT username, password FROM logintable WHERE username = '$username' and password = '$password'";
$sql_result = sqlite_query($db, $sql);
if (sqlite_num_rows($sql_result) != 1) {
echo "Login Failed.";
exit;
} else {
$_SESSION["username"] = $username;
header("Location: ".$_POST['redir']);
}
} else {
die ($sqliteerror);
}
} else {
header("Location: loginform.php");
}
?>