这是代码PHP登录脚本重定向
<?php
//Start session
session_start();
//Then we retrieve the posted values for user and password.
$username = $_POST['username'];
$password = $_POST['password'];
//Users defined in a SQLite database
$db = new PDO("sqlite:/www/test.db");
$result = $db->query("SELECT COUNT(*) FROM users WHERE Username = '$username' AND Password = '$password'");
if ($result > 0)
{
//If user and pass match any of the defined users
$_SESSION['loggedin'] = true;
// close the database connection
unset($db);
header("Location: index.php");
};
//If the session variable is not true, exit to exit page.
if(!$_SESSION['loggedin'])
{
// close the database connection
unset($db);
header("Location: login.html");
exit;
};
?>
数据库模式:
用户名TEXT NOT NULL PRIMARY KEY UNIQUE,密码文本
唯一的行数用户名='admin'和密码='admin'
任何想法为什么即使用户名和密码不在数据库中,脚本为什么每次都将index重定向到index.php?
在此先感谢
把一个exit();在header()后面停止进一步的执行。 – djot 2012-04-23 18:02:51