hello!

question, i want to unset all the session that i created on my script except for 1-3 sessions, can i use session_destroy to unset those sessions and exempt the 1-3 session that i dont want to be unset?

thanks!

Member Avatar for diafol

session_destroy will kill all known session variables DEAD (AFAIK).

Use unset() to kill off everything except your valuables:

$exempt = array("one","two","three"); //the keys to keep
foreach($_SESSION as $key => $val){
  if(!in_array($key,$_SESSION)unset($_SESSION[$key]);
}

NOT tested - looking at it, I've created an exempt array - it may be quicker to do a conditional of individual values using OR (||).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.