請問我一直在努力解決這個問題,但並沒有爲我工作。我有一個會話已開始,但在使用unset($_SESSION['variable']
註銷後,由於會話未設置,我無法重新登錄。如何解決未設置變量後會話不會啓動
請幫我一把。注意:我無法在取消設置變量後登錄。
//this is login.php
<?php
session_start();
ob_start();
$msg = "";
if (isset($_POST['login'])){
include "dbconnect.php";
if($_SESSION['emaill'] !== NULL){
$emaill= $_SESSION['emaill'];
$passWord = $_POST['passWord'];
if (empty($emaill && $passWord) == false){
$sql = "SELECT * FROM `sono` WHERE `eMail`='$emaill' && `passWord`='$passWord'";
$check = mysqli_query($dbconnect, $sql) or die (mysqli_error($dbconnect));
$result = mysqli_num_rows($check);
if ($result > 0){
$emaill= $_SESSION['emaill'];
header ('location: home.php');
exit();
} else
$msg = "<p style='color: red; padding-left: 10px'>Invalid password or email address</p>";
} else
$msg = "<p style='color: red; padding-left: 10px'>Please enter your email and password to login</p>";
} else
$msg = "<p style='color: red; padding-left: 10px'>My scripts not working yet</p>";
}
?>
// this is for logout
<?php
session_start();
if (isset($_SESSION['emaill'])){
unset($_SESSION['emaill']);
header('location: login.php');
}
?>
[PHP:「通知:未定義變量」和「通知:未定義指數」]的可能的複製(http://stackoverflow.com/questions/4261133/php- notice-undefined-variable-and-notice-undefined-index) –
在註銷時,你銷燬'$ _SESSION ['emaill']'但是當你再次嘗試登錄時,你不檢查第8行中是否存在'email' 'if($ _ SESSION ['emaill']!== NULL){'在嘗試使用它之前 – RiggsFolly