← CodePrimer
PHP Beginner Auth

Destroy a PHP session

How do I log a user out?

session_destroy pattern.

Sample
<?php
session_start();
$_SESSION = [];
session_destroy();
header('Location: /login.php');
exit;

Notes

Clear $_SESSION then destroy; redirect after.

Keywords: logout · session_destroy · auth

Related

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share