How can PHP be used to implement a logout function for a protected website directory?
To implement a logout function for a protected website directory in PHP, you can unset the session variables related to the user authentication and redirect them to the login page. This will effectively log the user out of the protected area.
<?php
session_start();
// Unset all session variables
$_SESSION = array();
// Destroy the session
session_destroy();
// Redirect to the login page
header("Location: login.php");
exit;
?>
Related Questions
- How can one effectively debug and troubleshoot issues related to preg_match in PHP?
- What steps can be taken to create statistics similar to those generated by the IVHA (IMDB Vote History Analyzer) using imdbphp?
- How can the use of a database and WHERE IN clause improve the efficiency of filtering accounts in PHP?