Session_destroy() returns error

Asked

Viewed 116 times

0

I am making a page, and in parts, PHP use, but in one part gives an error in the log out. Follow the error:

Warning: session_destroy(): Trying to Destroy uninitialized Session on line 22.

Follows 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 thought it strange the error appeared, if I made the check.
Does anyone know what it can be?

  • 1

    The session_start should be the first thing to be started on your script before any echo or output. What is it doing inside the if ?

1 answer

1

Use like this:

session_start();
if (isset($_SESSION)) {
    session_destroy();
}
  • But that would cause another problem, start a session already started. I edited up there, put the whole block.

  • what I have found so far you need to start the Session page to then give a destroyer. You came to test at least ?

  • I didn’t test, did you get to see the block? in: 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'])) .

  • I did not test session_start no if but from what I see with all the people here we use the form starts and destroys things so direct

  • I used what you sent, and as I said, it was wrong: A Session had already been Started - ignoring session_start()

  • only that it needs to be at the top of the page but the session_start of the same error

  • It makes no sense, the same way will make the mistake

  • beauty so many people are having trouble. because it is the solution that works. http://www.portugal-a-programar.pt/topic/58548-session-destroy-nao-destroi/

  • or if you want to use your own answer so stack http://stackoverflow.com/questions/5752858/warning-session-destroy I think it gets easier

  • It continues the same thing. I already put session_start() and gave the error above.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.