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.