简体   繁体   中英

How unset $_SESSION when refresh page in PHP, AJAX?

I want how destroy/unset the $_SESSION when the user refresh page or enter the website. It's possible?

Add this line to the top of the page on which you wish to unset the session:

<?php session_destroy(); ?>

See session_destroy on PHP.net

You can either destroy whole session data through <?php session_destroy(); ?> <?php session_destroy(); ?> or

<?php session_unset(); ?>

OR

you can unset particular key through unset($_SESSION[$key])

Yes, it's possible. you can use either php or javascript to unset/destroy session.

If you want to unset only one variable of session array. use :

foreach(array_keys($_SESSION) as $k) unset($_SESSION[$k]);

如果您想清除所有会话,只需使用

session_destroy();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM