Kano Posted March 16, 2007 Share Posted March 16, 2007 Hi there, I wish to unset some but not all $_SESSION variables. for example, i wish to keep $_SESSION['auth'] and $_SESSION['wscemail'] and destroy all others. can someone help? thanks. Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 16, 2007 Share Posted March 16, 2007 Something like this, maybe: <?php function sessionReset($keysToKeep) { // hold your temp values $temp = array(); if (is_array($keysToKeep)) { foreach ($keysToKeep as $k => $v) { $temp[$k] = $v; } } // Clear session unset($_SESSION); $_SESSION = array(); // assign temp back to session if (count($temp) > 0) { foreach ($temp as $k => $v) { $_SESSION[$k] = $v; } } } // Reset your session: sessionReset(array('auth', 'wscemail')); ?> Quote Link to comment Share on other sites More sharing options...
Kano Posted March 16, 2007 Author Share Posted March 16, 2007 Genius! Nice one mate! You wan't to see what I had, haha. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.