开发者

Session unset unsetting every variable?

开发者 https://www.devze.com 2023-03-31 18:04 出处:网络
I only want to unset play_mode however the second line also unsets landing_site. Why is this happening?

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['la开发者_JAVA技巧nding_site'];


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']).


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!


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']);


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

0

精彩评论

暂无评论...
验证码 换一张
取 消