Skip to content
Advertisement

Why is my session unset/ destroy not working?

On my page I have a session being created which can be accessed and called fine usually. However, I am adding a logout button which links to logout.php which only contains the lines

session_unset();
session_destroy();

Noting out the session_destroy, I’ve noticed that there is no error, but nothing happens to the current session. However, session_destroy is giving the following error. Similar questions show that this is because people have not called session start, but the session has been started in my login.php

error

Advertisement

Answer

You got error in your logout.php page. You wrote only two lines but try to add one line at the top of the page in your PHP scope.

session_start();
session_destroy();

It will work…!!!

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement