[英]php login page sessions
我創建了一個注冊頁面,該注冊頁面運行得很好,該信息已插入到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>
首先知道什么是die()
http://php.net/manual/en/function.die.php
您可能要使用JavaScript重定向來執行此操作,因為您想顯示一條消息。
使用3秒鍾或所需的set_timeout()
重定向腳本在頁面上放置JS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.