I am using session variables to control logins and page access. I use variables to control different user groups that a user belongs to, so I have quite a few session variables.
I also use a session variable to remember the users last visited page upon refresh.
When the user logs out, I use session_destroy(); to remove all variables. What i would like to do is to maintain the last visited page variable even after the user has logged out.
I think I could do it by using the unset function on every other variable, but there are a lot, and was wondering if there was an easier way?
Thanks Eds
you can try below code for this,
$Arr_not_destoy_session = array('last_visited_id');
foreach($_SESSION as $sees_key => $sess_val ){
if(!in_array($sees_key, $Arr_not_destoy_session)){
unset($_SESSION[$sees_key]);
}
}
this will unset all the session variables except 'last_visited_id' only.you can also add more values in this array which you dont want to remove later on..
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With