Jump to content

[SOLVED] session unset


asmith

Recommended Posts

is there any php function to unset all the variabes together? (and maybe all but 1 or 2 )

 

i can unset a variable i had set  with :

 

unset($_SESSION[aaa]);

 

 

 

i want to know if i have for example 20 variables stored in session like above , how can i unset all without having to code 20 times "unset()" .

 

and if i want to unset 18 of them and keep 2 , what should i do ?

 

 

Link to comment
https://forums.phpfreaks.com/topic/81476-solved-session-unset/
Share on other sites

thanks for the tip ,

i read the php.net session unset too !

but i didn't get how to keep some session variables while unsetting others ?

 

in previous example how can i keep $_SESSION[aaa]  and unset all of the other session variabels ?  what about keeping more than one ?

Link to comment
https://forums.phpfreaks.com/topic/81476-solved-session-unset/#findComment-413639
Share on other sites

I wrote a user function for you since I do not think there is any php function to suit your needs

 

function fnUserSessionUnset($arrKeepVars=array())
{
foreach ($_SESSION as $strKey => $strValue)
{
	if (!in_array($strKey,$arrKeepVars))
	{
		unset($_SESSION[$strKey]);
	}
}
}

 

so if you like to keep 'aaa' and 'bbb' just use it like this

 

fnUserSessionUnset(array('aaa','bbb'));

 

hope its helpful

Link to comment
https://forums.phpfreaks.com/topic/81476-solved-session-unset/#findComment-413646
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.