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
- How can PHP developers ensure data integrity when dealing with relational database tables in MySQL?
- What are the best practices for securing PHP scripts against SQL injections when using user input in queries?
- What are some best practices for designing a user-friendly and easy-to-use link tracking script in PHP?