Session_destroy () cannot take effect immediately. how can this problem be solved?

Source: Internet
Author: User
Session_destroy () cannot take effect immediately. use & lt; a & gt; to link to a php page in html. the php page will destroy the session, but the session still exists when the page is opened, the session can be destroyed only once the php page is refreshed. The two statements $ _ SESSION & nbsp; array (); session_destroy (); & nbsp; & session_destroy () on this page cannot take effect immediately.
Link to a php page in html. the php page will destroy the session. However, when the page is opened, the session still exists. the session can be destroyed only once the php page is refreshed. This page has two statements $ _ SESSION = array (); session_destroy (); session_start () enabled.
What is the situation?

------ Solution --------------------
Run session_destroy () on the B page. the previous session naturally exists. otherwise, session_destroy () is unnecessary.
You can only refresh the page B to find that the session is missing.
Because for users, session_destroy () is only a command to cancel the sessionid in the 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:

In this case, the page has not ended, and the current session will not disappear.

Connection_aborted () can be used to check whether the client is disconnected, but it needs to output content on the page, so ob_flush (); flush ();
The problem is that these two statements will cause the page where the session is destroyed to fail to be executed normally, that is, the session must be refreshed manually to be destroyed.


Therefore, is there any other way to disable this loop when the client is disconnected. Or is there any other way to normally execute the page where the session is destroyed.
Is the problem ob_flush (); flush? What should I do?

I am doing this to prevent users from logging on to the server for a long time. Is there any other way?


Your page has not ended, and the session on the current page has not been updated to the file. This is why session_destroy () cannot take effect immediately.
Add session_write_close (); to session_destroy (); to 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.