gpt4 book ai didi

php - session_destroy() 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:57:43 28 4
gpt4 key购买 nike

我的session_destroy() 不工作。当我以用户身份注销并返回浏览器时,显示用户在线。我在哪里有错误?谢谢。 :-)

文件登录.php

<?php
require_once('functions.php');
if(isset($_POST['submit'])){
if((isset($_POST['username']) && $_POST['username'] != '') && (isset($_POST['password']) && $_POST['password'] != '')){
$connection = conectDatabase();
$query = "SELECT * FROM users WHERE username='" . $_POST['username'] . "' AND password='" . $_POST['password'] . "';";
$result = $connection->query($query);
if ($result->num_rows >0){
session_start();
$_SESSION['username'] = $_POST['username'];
header('LOCATION: users.php');
} else {
echo '<p class="formMessage">Username/password do not match !</p>';
}
} else {
echo '<p class="formMessage">Username/Password field is empty</p>';
}
}
?>

文件函数.php

<?php
function conectDatabase() {
$connection = new mysqli('localhost', 'root', '', 'DB');

if(mysqli_connect_errno()) {
die("error DB: " . mysqli_error() . "(" . mysqli_connect_errno() . ").");
}
return $connection;
}
?>

文件 logout.php

<?php 
session_start();
session_destroy();
header('LOCATION: login.php');
?>

最佳答案

修改文件logout.php如下:

<?php 
session_start();
session_destroy();
unset($_SESSION);
session_regenerate_id(true);
header('LOCATION: login.php');
?>

关于php - session_destroy() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442054/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com