Phpsession cannot be deleted. The three interfaces are login. php, logout. php, and index. php.

Source: Internet
Author: User
Phpsession cannot be deleted. The three interfaces are login. php, logout. php, and index. php login. php.
The account password will not be sent, and the code for setting the session will be shown to you.
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 "logon successful ";
Echo "quit ";
} Else {
Echo "logon failed ";
}

Logout. php
// Method 1
Session_start ();
$ _ SESSION = array (); // clears the $ _ SESSION array.
Setcookie (session_name (), "", time ()-1); // clear the cookie
Session_destroy (); // delete this SESSION

// Method 2
Session_start ();
Unset ($ _ SESSION ['userid']);
Unset ($ _ SESSION ['useracc ']);
Unset ($ _ SESSION ['username']);
Unset ($ _ SESSION ['usertype']);
Session_destroy ();

// Execute all at the end
Ob_start ();
Header ("location: index. php ");
Ob_end_flush ();


But I don't know why. After I run logout. php (both write methods have been tried), I still log on to index. php and the data in the $ _ SESSION still exists. However, when I interrupt the logout. php jump, there is no value in the previous $ _ SESSION. Instruct experts on what the problem is!


Reply to discussion (solution)

Return to index. php. Does the browser return the button?
If the page is not reloaded, it will not change.

Return to index. php. Does the browser return the button?
If the page is not reloaded, it will not change.


No, it's the redirection jump in the header used,
It works on my local machine, but it won't work on the server.
The local machine uses iis on the apache server.

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
       
Logout. php
        

It seems that session_destory (); this method is invalid in IIS.
I first $ _ SESSION = array ();
Then in session_destory ();
It is found that all the data in the previous $ _ SESSION is returned, so it is consistent with the logon status,
Session_destory ();
Removed
I don't know what kind of errors or impacts will occur.
Hope the moderator can save

Session_unset ()

Session_unset ()
The statement used to clear the session array
Unset ($ _ SESSION ['userid ']);
Session_unset ();
$ _ SESSION = array ();
Either way, as long as session_destory () is written later ()
All the data is returned.

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.