Session_destroy () cannot take effect immediately

Source: Internet
Author: User
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?


Reply to discussion (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

a.php

 
  Se2


b.php
 
  

A page to the B page to destroy the session, and the B page then jump to the landing page, this time the session is still in, is the case

Visit a.php-b.php, login.php session disappears.
a.php

 
  Go b

b.php
 
  Go Login

login.php
 
  

I find the reason is not destroy problem. When a user logs in, a PHP page executes a dead loop that updates the user's login time every 30 seconds until the user leaves the current page.

while (true) {echo "\ n"; Ob_flush (); flush (); if (connection_aborted ()) exit;        /* Here is the current time written to the database */sleep (30);}



If you delete the Ob_flush (), flush (), the problem will be resolved, but then connnection_aborted () will not take effect, and the user will continue to update the page after it is closed. But if the two sentences are added, the session cannot be destroy and must be manually f5 before it can be deleted.

How can i solve this problem?

What do you want to???? What about death?

What do you want to???? What about death?


Periodically update the login time to the database, if the user stays online until the user closes the page

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

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?


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.



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.



Okay, thank you, no 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.