For logging out a user from my website, I am redirecting the page to logout.php
where I am using session_destroy() function. Even there also, logout functionality is not working without session_start()
function. By adding session_start() function before session_destroy()
function, I am able to logout the user successfully.
Why do I need to use session_start()
function everytime and in every page where I am doing something related to sessions?
Why do I need to use session_start() function everytime and in every page where I am doing something related to sessions?
So PHP knows which session to destroy. session_start()
looks whether a session cookie or ID is present. Only with that information can you destroy it.