- 2 years ago 96
PHP Question

How to fix session not starting after unsetting a variable

Please I have been trying to fix this but not working out right for me. I have a session started but after logging out using

, I am unable to login back as the session is not setting.

Please help me out. Note: I am unable to login after unsetting the variable.
//this is login.php

$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');
} 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
if (isset($_SESSION['emaill'])){
header('location: login.php');

Answer Source

before using $_SESSION['emaill'], check it with isset() like :

if( isset($_SESSION['emaill']) && $_SESSION['emaill'] !== NULL){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download