我想在用户点击注销链接时注销用户,但它有效,但存在问题。当我点击注销链接时,用户会注销并转到页眉页面,但如果我点击后退按钮,我会直接返回到上一页面而无需再次登录,这是不安全的。当用户注销时,我希望他们完全注销,重新登录的唯一方法是登录。有人可以帮忙吗?PHP将用户完全注销掉
<?php
include("connect.php");
//check if form is submitted
if ($_SERVER['REQUEST_METHOD'] != 'POST' ||
! isset($_POST['signin']))
{
// looks like a hack, send to index.php
header('Location: index.php');
exit;
}
if (empty($_POST["usernam"])) {
echo 'fill in username to sign in';
}
if (empty($_POST["pw"])) {
echo 'fill in password to sign in';
}
$sql = "SELECT pw FROM users WHERE usernam = ?";
$stmt = mysqli_prepare($conn, $sql);
if (!$stmt) {
echo mysqli_error($conn);
exit;
}
$stmt->bind_param('s', $_POST['pw']);
$stmt->execute();
if (!$stmt) {
echo mysqli_error($conn);
exit;
}
// we found a row with that username,
// now we need to check the password is correct
// get the password from the row
$stmt->bind_result($hashed_pwd);
$stmt->fetch();
if (password_verify($_POST['pw'], $hashed_pwd)) {
// password verified
header('Location: home.php');
} else {
echo 'Incorrect username or Password. <a href= index.php>Try again</a><br />';
}
?>
logout.php
session_start();
session_destroy();
header('location:index.php');
process2.php(登录):
include("connect.php");
//check if form is submitted
if ($_SERVER['REQUEST_METHOD'] != 'POST' ||
! isset($_POST['signin']))
{
// looks like a hack, send to index.php
header('Location: index.php');
exit;
}
if (empty($_POST["usernam"])) {
echo 'fill in username to sign in';
}
if (empty($_POST["pw"])) {
echo 'fill in password to sign in';
}
$sql = "SELECT pw FROM users WHERE usernam = ?";
$stmt = mysqli_prepare($conn, $sql);
if (!$stmt) {
echo mysqli_error($conn);
exit;
}
$stmt->bind_param('s', $_POST['pw']);
$stmt->execute();
if (!$stmt) {
echo mysqli_error($conn);
exit;
}
// we found a row with that username,
// now we need to check the password is correct
// get the password from the row
$stmt->bind_result($hashed_pwd);
$stmt->fetch();
if (password_verify($_POST['pw'], $hashed_pwd)) {
// password verified
header('Location: home.php');
} else {
echo 'Incorrect username or Password. <a href= index.php>Try again</a><br />';
}
那么你是如何做到这一点真的取决于你如何跟踪登录的用户。从登录脚本显示一些代码,这应该会给我们一些线索 – RiggsFolly
您是否在使用会话? – Fabio
我会更新我的问题 – mkd