Now we have our log in farm.
We can log in.
And we're redirected back to the index page when we log out though.
No redirect occurs.
To redirect.
First will include the file where the redirect function is and then call the redirect function.
After we've set the value in the session to false.
So now we can log in when we enter the correct credentials and we redirected to the index page.
Then when we log out we're logged out and redirected back to the index page as well.
However although we set this value in the session to files the same session still exists during the
time that the user was logged in.
We could have stood by other values in the session which will still exist.
So it's better when logging out to remove all sesshin values and completely destroy the current session.
We can do this using the session destroy function.
This destroys all the data in a session.
So instead of setting this value to false Lets call the session destroy function instead.
We still need to call session start so that the script knows we're working with the current session.
So if we try that by first logging in then when we click log out all the values in the session our destroyed
which includes the is logged in value so were locked out.
We can improve this however in the documentation for the session.
Destroy function.
It tells us that just calling the session destroy function on its own just destroys the data it doesn't
destroy the session itself to completely destroy the session.
You need to set of the session variables and also unset the session cookie.
You can do all that using this cold here.
So let's add this code to our logout script like that.
Basically what this does is first clear the sesshin global variable by setting it to a new array.
Then we check to see if the session is using cookies which it does by default.
And if so we use this code to remove the sesshin cookie in the browser.
We'll learn more about cookies later on.
So now if we log in again
when we log out we redirected back to the index page and the session has been completely destroyed.