PHP session_destroy() Function

What is session_destroy Function?
How to end or destroy session data in PHP?

Explanation

The "session_destroy()" function destroys all data registered to a session.

Syntax:


session_destroy(void)

Usually the session_destroy is called to end the session when the browser is closed, unlike cookies which have a specific time to end the session.

Example :


<?php
session_start();
$_SESSION = array();
session_destroy();
?>

In the above example first the session_start() is called and then an empty array is called, only then the session_destroy() is called, if session_start is not called the other two statements may not execute properly.

PHP Topics


Ask Questions

Ask Question