I have a single page site I'm working on that displays the contents of your current session. Users can clear the contents by clicking a link that triggers a $PHP_SELF?clear=1 - Before any headers are sent out, the script checks for $_GET['clear'], and if it's set, it does a session_destroy();. For some reason though, the contents of the session are STILL displayed until you do a refresh on the page. However, for some bizarre reason, if I call session_start() at the very beginning, call session_destroy(); and then session_start() AGAIN after the destroy, it seems to work like it's supposed to. Is this a bug, or is it working properly? Also - I'm sure there's a better method than this - Any suggestions on what that might be? If there are no better methods well... Are there any downsides to what I'm doing?
Below is a "sample" version of the script, to give you an idea of what I mean incase my ramblings above didn't make sense. Thanks!. <?php session_start(); // Start the session if (isset($_GET['clear'])) { session_destroy(); // If they chose to clear the session, then we do so } session_start(); // Start it again; it works for whatever reason ?> <html><body> (some other stuff) <? /* Here I just print out whatever's in the session. Unless session_start is called the second time after the destroy, a user will have to click refresh before the data appears to be gone */ if (isset($_SESSION['states'])) { foreach ($_SESSION['states'] as $value) { echo "$value<br/>\n"; } } // and lastly, here's our "clear session" link below ?> <a href="index.php?clear=1">Clear the session</a> </body></html> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php