How can a single session variable be deleted in PHP?
To delete a single session variable in PHP, you can use the unset() function to unset the specific session variable that you want to delete. This function removes the variable from the $_SESSION superglobal array, effectively deleting it from the session.
<?php
session_start();
// Set a session variable
$_SESSION['example_var'] = 'value';
// Delete a specific session variable
unset($_SESSION['example_var']);
?>
Keywords
Related Questions
- What are the potential security risks of using .tpl files for PHP code containing sensitive information like passwords?
- What are the potential issues with using margin, padding, and border in CSS when defining element widths in PHP?
- What are the benefits of using phpMyAdmin compared to writing custom PHP scripts for database management tasks?