我的PHP页面上的注销系统有问题。当我尝试注销第二个帐户时,在注销第一个帐户之后,它将向我显示第一个帐户的会话详细信息。
所以问题出在下面:我已经为网站创建了注册+登录/注销系统。该站点从phpmyadmin连接到数据库。 我创建了4个帐户。它们在数据库中都可以。 当我登录第一个帐户时,一切正常。此后,我注销并尝试使用新帐户登录。登录显示为成功,但会话名称和所有其他详细信息与第一个用户的帐户一起显示。
这是我的登录名
<form method="post">
<input type="email" name="email" class="rlform-input" placeholder="Username" required>
<input type="password" name="password" class="rlform-password" placeholder="Password" required>
<input type="submit" class="rlform-btn" name="signIn" value="Login">
</form>
这是注销:
<?php
session_start();
$_SESSION = array();
session_destroy();
header("Location: login.php");
?>
我还尝试了下一个注销代码,但没有结果:
<?php
session_start();
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"] );
}
// Finally, destroy the session.
session_destroy();
header("Location: index.php");
?>
登录代码:
<?php
session_start();
if(isset($_SESSION['login_id'])){
if (isset($_SESSION['pageStore'])) {
$pageStore = $_SESSION['pageStore'];
header("location: $pageStore");
}
}
if (isset($_POST['signIn'])) {
if (empty($_POST['email']) || empty($_POST['password'])) {
echo "Username & Password should not be empty";
}
else
{
$email = $_POST['email'];
$password = $_POST['password'];
include('config.php');
$sQuery = "SELECT id, password from account where email=? LIMIT 1";
$stmt = $conn->prepare($sQuery);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($id, $hash);
$stmt->store_result();
if($stmt->fetch()) {
if (password_verify($password, $hash)) {
$_SESSION['login_id'] = $id;
if (isset($_SESSION['pageStore'])) {
$pageStore = $_SESSION['pageStore'];
}
else {
$pageStore = "index.php";
}
header("location: $pageStore");
$stmt->close();
$conn->close();
}
else {
echo 'Invalid Username & Password';
}
} else {
echo 'Invalid Username & Password';
}
$stmt->close();
$conn->close();
}
}
?>