Session_destroy () does not take effect immediately, how to solve

Source: Internet
Author: User
Session_destroy () cannot take effect immediately
In the HTML link to a PHP page, the PHP page will destroy the session, but when the page opens, the session is still there, only to refresh the PHP page again to destroy the session. The page is two statements $_session = Array (); Session_destroy (); Session_Start () is already open.
Excuse me, what's the situation?

------Solution--------------------
You execute Session_destroy () in the B page; The former session naturally exists, otherwise there is no need to Session_destroy (); The
You only have to re-enter the B page (such as refresh) to find that the session is not
Because for the user, Session_destroy () is simply the instruction to send the SessionID in the logout cookie
------Solution--------------------
a.php

Session_Start ();
$_session[' name '] = "Kobe";
?>
Se2


b.php

Session_Start ();
$_session = Array ();
Session_destroy ();
Var_dump ($_session[' name ');
?>

------Solution--------------------
Reference:
Quote: Reference:

So the page has never ended, of course, the current session will not disappear.

connection_aborted () This sentence can check whether the client is disconnected, but it does need to output the content in the page, so add Ob_flush (); flush ();
The problem is that the page that will cause the session to be destroyed does not work properly, i.e. it must be manually refreshed to destroy the session


So there is no other way to close this loop when the client disconnects. Or there is no other way to normally perform the destruction session of that page.
Is there a problem with ob_flush (); flush (); What do we do?

I do this is to prevent users from long-time not landing is kicked off the job, there are other ways?


Your page has not ended and the session of the current page has not been updated to the file. This is why Session_destroy () cannot take effect immediately.
In Session_destroy (); After adding Session_write_close (); can solve this problem.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.