PHP session can not be deleted, three interface login.php,logout.php,index.php

Source: Internet
Author: User
login.php
Verify the account password is not sent, send the code to set the session for everyone to see
Session_Start ();
$_session["userid"]= $rs [ID];
$_session["USERACC"]= $rs [Acc '];
$_session["username"]= $rs [Name];
$_session["usertype"]= "user";
Ob_start ();
Header ("location:index.php");
Ob_end_flush ()

index.php
if ($_session[' userid ']!= ') {
echo "Login Successful";
echo "Exit";
}else{
echo "Login Failed";
}

logout.php
The first form of a notation
Session_Start ();
$_session=array ();//Empty the $_session array
Setcookie (Session_name (), "", Time ()-1); Empty the cookie
Session_destroy (); Delete this session

The second type of notation
Session_Start ();
unset ($_session[' userid ');
unset ($_session[' USERACC ');
unset ($_session[' username ');
unset ($_session[' usertype ');
Session_destroy ();

And finally all executed
Ob_start ();
Header ("location:index.php");
Ob_end_flush ();


But I do not know why, after the execution of logout.php (two kinds of writing have tried) back to index.php or login success, the $_session inside the data are still there. But I interrupted logout.php jump in front of the $_session inside is no value. Please master guide what is the problem!


Reply to discussion (solution)

Back to index.php, is it through the browser back button?
That doesn't reload the page of course it won't change

Back to index.php, is it through the browser back button?
That doesn't reload the page of course it won't change


No, that's the redirect jump in the header that was used,
It's all right on my own machine, not on the server.
This machine is using an Apache server that is IIS

There must be something wrong with you!
Test code:
index.php

   
login.php
    
logout.php
    

There must be something wrong with you!
Test code:
index.php

      
login.php
!--? Phpsession_start (); $_session["userid"] = 1;ob_start (); Header ("Location:  index.php "); Ob_end_flush ();  
logout.php
!--? Phpsession_start (); Session_destroy ();//Delete this session Ob_start (  ); Header ("location:index.php"); Ob_end_flush ();   

now looks like session_destory (); This method is invalid in IIS
I $_session = Array (); The
is then session_destory ();
found that the previous $_session inside the data are back, so the consistent is the login status,
behind the session_destory ();
is removed
do not know what kind of error or impact this will occur.
want to save the moderator

Session_unset ()

Session_unset ()
The statement that empties the SESSION array uses the
unset ($_session[' userid '); this
Session_unset (); this
$_session = Array (); This
, whatever it is, One, as long as the back is written on the Session_destory ()
The data inside is all back again.

  • 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.