我已经创建了一个完全正常的注册页面,信息被插入到mysql中,但是当我想要登录时,由于某种原因,它并没有将我引导到account.php。它说"重定向到:account.php有人可以帮我解决这些问题。我已经把它放在login.php和account.php
中由于
的login.php
$submitted_username = '';
if(!empty($_POST))
{
$query = "
SELECT
id,
forename,
surname,
Studentid,
username,
salt,
password,
email
FROM users
WHERE
username = :username
";
$query_params = array(
':username' => $_POST['username']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
not.
switch it to true.
$login_ok = false;
$row = $stmt->fetch();
if($row)
{
$check_password = hash('sha256', $_POST['password'] . $row['salt']);
for($round = 0; $round < 65536; $round++)
{
$check_password = hash('sha256', $check_password . $row['salt']);
}
if($check_password === $row['password'])
{
$login_ok = true;
}
}
members-only page
// again
if($login_ok)
{
unset($row['salt']);
unset($row['password']);
$_SESSION['user'] = $row;
// Redirect the user to the private members-only page.
header("Location: account.php");
die("Redirecting to: account.php");
}
else
{
print("Login Failed.");
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}
}
account.php
<?php
require("common.php");
if(empty($_SESSION['user']))
{
header("Location: Login.php");
die("Redirecting to Login.php");
}
?>
Hello <?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES, 'UTF-8'); ?>, secret content!<br />
<a href="edit_account.php">Edit Account</a><br />
<a href="logout.php">Logout</a>
答案 0 :(得分:0)
首先要知道什么是die()
http://php.net/manual/en/function.die.php
您可能希望使用JavaScript重定向来执行此操作,因为您要显示消息。
在您的页面上放置一个JS,其中包含set_timeout()
3秒内的重定向脚本或您想要的任何内容。