PHP 8 Beginner Auth · 1 min read

Destroy a PHP session

Start the PHP 8 learning path »

❮ PHP 8 Home All Tutorials ❯

How do I log a user out?

session_destroy pattern.

Example

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

Line-by-Line Walkthrough

Clear $_SESSION then destroy; redirect after.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…