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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.