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. Link to comment https://forums.phpfreaks.com/topic/42991-solved-_session/ 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')); ?> Link to comment https://forums.phpfreaks.com/topic/42991-solved-_session/#findComment-208788 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 Link to comment https://forums.phpfreaks.com/topic/42991-solved-_session/#findComment-208797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.