What is the function used to destroy a session in PHP?
To destroy a session in PHP, you can use the session_destroy() function. This function will unset all session variables and destroy the session data. It is commonly used when a user logs out of a website or when you want to clear all session data.
<?php
// Start the session
session_start();
// Unset all session variables
$_SESSION = array();
// Destroy the session
session_destroy();
?>
Keywords
Related Questions
- What are common pitfalls when using the wordwrap function in PHP?
- In what ways can PHP developers optimize the process of retrieving, resizing, and storing images from a MySQL database to improve overall performance and user experience?
- Are there alternative methods to secure PHP applications if SSL cannot be implemented?