Want to remove some data that you've stored in a session? In that case, you can use the unset function. Here's an example; say that you've stored the temperature as 72 in a session using a data item named temperature, as you see in phpsessionunset.php: <H1>Removing data from sessions</H1> <?php session_start(); $_SESSION['temperature'] = "72"; ?> Stored the temperature as 72 degrees. <BR> To read the temperature in a new page, <a href="phpsession2.php"> click here</a>. You can see what this page looks like in Figure 9-17. Figure 9-17. Removing data from sessions.This page links to phpsessionunset2.php, where we'll unset the temperature item: Removing the "temperature" item....<BR> <?php session_start(); unset($_SESSION["temperature"]); ?> To continue, <a href="phpsessionunset3.php">click here</a>. You can see what this page looks like in Figure 9-18. Figure 9-18. Removing an item.Finally, in the linked-to page, phpsessionunset3.php, we'll search for the temperature item: <H1>Removing data from sessions</H1> Looking for the temperature item...<BR> <?php session_start(); if(isset($_SESSION["temperature"])){ echo "The temperature is " . $_SESSION["temperature"]; } else { echo "Can't find the temperature item.";} ?> You can see the results in Figure 9-19as expected, the temperature item has indeed been removed. Perfect. Figure 9-19. The item was removed.That completes our work with sessionsand that completes our book. We've come far in this book, from the very beginning up to some advanced techniques. PHP gives you outstanding power, and I hope you enjoy working and playing with it as much as I doall that's left is to put it all to use for yourself! |