我已经创建了一个运行良好的注册页面,信息被插入到 mysql 中,但是当我想登录时,由于某种原因它没有引导我到 account.php。它说“重定向到:account.php 有人可以帮我处理代码吗?我已经把什么放在了 login.php 和 account.php
谢谢
登录.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>
最佳答案
先知道什么是die()
http://php.net/manual/en/function.die.php
您可能希望使用 JavaScript 重定向来执行此操作,因为您希望显示一条消息。
在 3 秒或任何你想要的 set_timeout()
中使用重定向脚本在你的页面上放置一个 JS。
关于php登录页面 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28613354/