lisovaccaro
lisovaccaro

Reputation: 33956

Session unset unsetting every variable?

I only want to unset play_mode however the second line also unsets landing_site.

Why is this happening?

session_start();

session_unset($_SESSION['play_mode']);

echo $_SESSION['landing_site'];

Upvotes: 0

Views: 745

Answers (4)

swordfish
swordfish

Reputation: 4995

From php.net

void session_unset ( void )
The session_unset() function frees all session variables currently registered.

If you want to unset just one variable then just use unset.

unset($_SESSION['play_mode']);

Upvotes: 1

Robus
Robus

Reputation: 8259

session_unset
The session_unset() function frees all session variables currently registered.
Try this instead:

unset($_SESSION['play_mode']);

[edit]
This question needs more people linking the manual!

Upvotes: 1

user557846
user557846

Reputation:

you want unset() for a single var not session_unset() the whole session

Upvotes: 0

user554546
user554546

Reputation:

Because, as per the documentation,

The session_unset() function frees all session variables currently registered.

Also, session_unset() takes no arguments.

If you only want to unset $_SESSION['play_mode'], then just do unset($_SESSION['play_mode']).

Upvotes: 2

Related Questions