Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Logging Out3:13 with Alena Holligan
The final part of logging in, is a logout system. We have already covered all the needed functionality, so let's put the pieces together to allow our users to logout.
Alternative Syntax for Control Structures
PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.
The final part of logging in is a log out system.
We've already covered all of this, so it should not be anything new.
We need to create a do log out procedure.
Let's close up the ink folder.
Now, we're going to set the bad cookie and then redirect.
Let's go to our function and copy these two lines.
Now, let's change our navigation and
check if the user should see the log in or log out.
If not is authenticated,
When we're breaking up our conditional statement over multiple code blocks,
it can be easier to follow if we use a secondary format using a colon and,
We can also add an else for our log out link.
Because we're using the is authenticated function in our navigation file, we'll
need to add the bootstrap file to the rest of our login and register pages as well.
We also need to clean up our home page.
We'll move the bootstrap file to the top.
And remove this extra logged in code.
Let's take a look at this in the browser.
While we're logged in, we see the link to log out.
And when we log out, we see the links to log in or register again.
Also, when we click on the Add Book, we get redirected to the log in page.
You need to sign up for Treehouse in order to download course files.Sign up