← CodePrimer
PHP
Beginner
Auth
Destroy a PHP session
How do I log a user out?
session_destroy pattern.
<?php
session_start();
$_SESSION = [];
session_destroy();
header('Location: /login.php');
exit;
Notes
Clear $_SESSION then destroy; redirect after.
Keywords: logout · session_destroy · auth
Related
PHP
Embed PHP inside HTML
How do I mix PHP and HTML?
PHP
PHP comments
How do I write comments in PHP?
PHP
PHP variable rules
What are the rules for PHP variables?
PHP
echo vs print
Should I use echo or print?
PHP
PHP scalar data types
What data types does PHP have?
PHP
Debug with var_dump
How do I inspect a variable’s type?