How can a logout functionality be implemented in PHP using link parameters?
To implement a logout functionality in PHP using link parameters, you can create a logout link that when clicked, will pass a parameter to the PHP script indicating that the user should be logged out. The PHP script can then unset the session variables and destroy the session, effectively logging the user out.
<?php
session_start();
if(isset($_GET['logout'])) {
session_unset();
session_destroy();
header("Location: login.php");
exit;
}
?>
<a href="?logout=true">Logout</a>
Related Questions
- How can the utilization of external classes or functions, such as Array2String, impact the overall performance and stability of a PHP application?
- What are the advantages of using DATERANGE in PHP for managing date ranges in database queries?
- What are the limitations of using IP-based bans for user restrictions?