我有登錄和註銷頁面,但無法註銷,總是說用戶已經登錄。這是我的登錄頁面:session_destroy無法破壞會話php
<?php
session_start();
include_once("connection.php");
if(isset($_POST) & !empty($_POST)) {
$userName = mysqli_real_escape_string($connection, $_POST['userName']);
$userPassword = md5($_POST['userPassword']);
$login = "SELECT * FROM `users` WHERE userName = '$userName' and password = '$userPassword'";
$result = $connection->query($login);
while ($val = mysqli_fetch_array($result))
{
$isAdmin = $val['isAdmin'];
$companyID = $val['companyID'];
$branchID = $val['branchID'];
$ID = $val['ID'];
}
$count = mysqli_num_rows($result);
if($count == 1){
$_SESSION['userName'] = $userName;
setcookie("userID", $ID);
setcookie("companyID", $companyID);
setcookie("branchID", $branchID);
if(!$isAdmin){
header('location: home.php');
}
else {
header('location: admin/home.php');
}
}
else {
$fmsg = "Wrong user name";
}
}
if(isset($_SESSION['userName'])){
$smsg = "Already loggedin";
}
?>
這裏是loggout頁:
<?php
session_start();
session_destroy();
unset($_COOKIE['companyID']);
unset($_COOKIE['userID']);
unset($_COOKIE['branchID']);
setcookie('companyID', null, -1, '/');
setcookie('userID', null, -1, '/');
setcookie('branchID', null, -1, '/');
header('location: index.php');
?>
我怎麼能解決這個問題?任何人都可以幫我嗎?還有一個附加的圖像顯示餅乾。
很抱歉,但couldnot進行任何更改。我有同樣的問題:( –
這是我的註銷頁面現在 '' –
如果您打算將cookie的時間設置爲減號,我的意思是這並不能解決你的問題,但它沒有意義 –