With most of the pieces of the puzzle in place, let's go through the process of changing the layout for users, depending on if they are logged in or not.
1. Let's add a function called
current_user
inclasses/user.php
, so that we can retrieve the current user's username from the session.public static function current_user() { session_start(); return $_SESSION['username']; session_write_close(); }
2. Add a public static function called
is_authenticated
intoclasses/user.php
so we can see if the user is authenticated or not.public static function is_authenticated() { if (self::current_user()) { return true; } else { return false; } }
3. Now that we have our authentication in order, let's tighten up the navigation in
layout.php
, so that different navigation items are displayed depending on if the user is logged in or not.<ul class="nav"> <li><a href="<?php echo $this->make_route('/') ?>">Home</a></li> <?php...