Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

session_destroy

Deletes the session data on the server.

Syntax

session_destroy(): bool

Return value

bool`true` on success.

Examples

Logging a user out:

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

Notes

The $_SESSION array stays filled until the end of the request — that is why it is cleared separately.

See also

Related recipes

In the tutorial

  • Registration and login — How to build registration and login in PHP — the users table, password hashing, checking on login, the session, protected pages and logout.

Thanks for reading!

Donate to the site — we work hard for you.