How to fix session not starting after unsetting a variable

Amjos.com

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 unset($_SESSION['variable'], 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
<?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');
    }
?>
Ranjit Shinde

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

if( isset($_SESSION['emaill']) && $_SESSION['emaill'] !== NULL){
----
---
}

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Unsetting a variable in Velocity

Unsetting Superglobal Variable Properly

Unsetting an exported environment variable

Unsetting an item from an array in a session

Triggering an error on unsetting a traced variable

Unsetting environment variable with an empty name

Unsetting several indexes starting with a predetermined prefix

GNOME session not starting after filesystem corruption

how to update a session variable in after the reload of every page in laravel

How to call an AJAX function after setting a session variable?

How to delete session variable after use in Django templates

how to clear session variable after a user control unload

Unsetting an environment variable vs. setting it to zero

Rebase array keys after unsetting elements

How to fix Zend DbTableGateway read/destroy infinite loop after session expiration?

How to fix the section starting under a previous section?

how to Fix undefined variable?

How to change the starting directory of a tmux session?

How to unset $_SESSION variable?

How to store a variable in session?

How Does Setting/Unsetting MASM Flags Work

How to update a session variable of a specific session

Django Session Variable Is Accessible Even After Deletion

session value changes after changing of associated variable

PHP after redirect the session variable changes to false

Unable to retrieve session variable after setting it

Vue Syntax error after binding a session variable

PHP Session Variable Not Working After Page Redirect

New $_SESSION variable not created after query?