Session_destroy () returns error

0

I'm making a page, and in parts, I use PHP, but in one part it gives an error in the log out. Here is the error:

  

Warning: session_destroy (): Trying to destroy uninitialized session on line 22.

Follow the line:

if ((!$loginrequired) or ((isset($_SESSION) or !isset($_SESSION) and session_start()) 
    and (isset($_SESSION['lname']) and isset($_SESSION['lpass'])) 
    and isValidLogin($_SESSION['lname'], $_SESSION['lpass']))) {

    header("location:/questions/home");
} else {
    unset($_SESSION['lpass']);
    unset($_SESSION['lname']);
    if (isset($_SESSION)) {
        session_destroy();
    }
}

I found it strange that the error appeared, if I did the check. Does anyone know what it can be?

    
asked by anonymous 12.09.2014 / 20:38

1 answer

1

Use this way:

session_start();
if (isset($_SESSION)) {
    session_destroy();
}
    
12.09.2014 / 20:50