From the course: PHP with MySQL Essential Training: 2 Build a CMS

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Log out a user

Log out a user

- [Instructor] Now that we've learned how to authenticate a user and how to have pages that require that authorization, we need to learn how to remove the authorization or to log out a user. We already have a placeholder page for logging out, logout.php and we even have a link for it at the top of our page. But if we click that, it doesn't actually log us out. We stay logged in because it's not removing the hand stamp, that admin ID that we stored in the session, it's just unsetting session username, which was just a convenience that we had earlier. So what I'm going to do is I'm going to switch to auth_functions.php and right here below login admin, I'm going to add a new function called log out admin. This is also included the exercise files if you want to get it from there, and it's going to do the exact opposite of logging in the user, it's going to unset all of those session IDs, one for admin_id, last_login, and username. So it handles all the business of logging a user out. I…

Contents