0

I have a certain session variable that is actually an array. I want to delete the entire array variable but cannot make it happen.

_SESSION VAR

$_SESSION['auth']['id']
$_SESSION['auth']['username']
$_SESSION['auth']['role']

I tried unset($_SESSION['auth']) but it does not work. Do I need to unset each 2nd level array individually using unset()?

Thanks.

3
  • 2
    unset() definitely does work. Your problem must be elsewhere. Commented Mar 23, 2012 at 19:48
  • 1
    Like Brad said, unset must work. Did you try setting $_SESSION['auth'] to null ? Commented Mar 23, 2012 at 19:49
  • Ok, totally my bad. Long story...I built a routine that auto loads the session var from a persistent cookies. During my logout I attempted to delete the cookie and it failed. Subsequently, my _SESSION var got rebuilt by my backend script -- so there it was working. And the unset() was actually working too. It was just not effectively deleting the cookies. Sorry for the trouble and the silly question. But thanks for chiming in everyone. Commented Mar 23, 2012 at 19:57

2 Answers 2

1

unset should be working :S As Artjom Kurapov also pointed out, it might have to due with the session not being started.

But anyhow, have you tried just doing

$_SESSION['auth'] = array();

Or if you don't care about the session at all, you could do session_unset or session_destroy

Sign up to request clarification or add additional context in comments.

2 Comments

i think you meant to use a single "=" there. Otherwise you're just comparing it.
hah, lol, completely missed that ^^ Guess that's my penalty for trying to give a quick answer :P. But thx for pointing out @showerhead, it's now edited to the correct thing.
1

Maybe you don't have session_start() somewhere before?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.