Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
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.
0:00
We've already covered all of this,
so it should not be anything new.
0:04
We need to create a do log out procedure.
0:09
Let's close up the ink folder.
0:13
DoLogout.php.
0:17
Require,
0:26
Inc/bootstrap.php.
0:34
Now, we're going to set the bad cookie and
then redirect.
0:39
Let's go to our function and
copy these two lines.
0:44
Now, let's change our navigation and
0:53
check if the user should see the log in or
log out.
0:56
If not is authenticated,
1:06
When we're breaking up our conditional
statement over multiple code blocks,
1:15
it can be easier to follow if we use
a secondary format using a colon and,
1:20
and if.
1:24
We can also add an else for
our log out link.
1:34
Procedures/doLogout.
1:53
Because we're using the is authenticated
function in our navigation file, we'll
1:59
need to add the bootstrap file to the rest
of our login and register pages as well.
2:05
We also need to clean up our home page.
2:31
We'll move the bootstrap file to the top.
2:38
And remove this extra logged in code.
2:42
Let's take a look at this in the browser.
2:49
While we're logged in,
we see the link to log out.
2:58
And when we log out, we see the links
to log in or register again.
3:02
Also, when we click on the Add Book,
we get redirected to the log in page.
3:07
You need to sign up for Treehouse in order to download course files.
Sign up