Session is used in php to record user information across pages. It is used for Server login. However, the Environment configured today finds that the session cannot be transmitted normally, how can I solve the problem of saving phpsession? The details are as follows. Session is used in php to record user information across pages. It is used for Server login. However, the Environment configured today finds that the session cannot be transmitted normally, how can I solve the problem of saving php sessions? The details are as follows.
Script ec (2); script
Because the correct verification code result has been encrypted and saved in the session, all the verification codes used for input will be compared with the session to determine whether the verification code is entered incorrectly!
Since it is always displayed: "Incorrect verification code entered"
This indicates that the result of saving the session may be incorrect. Then, dump the session and find that the result is null ......
Solution:
Use phpinfo to view the session information, find the Save path of the session, and set the write permission for the session.
If the problem persists, refer to the following:
Now let's leave the cookie to use the session. There are three main ways:
1. Set session. use_trans_sid = 1 in php. ini or enable the-enable-trans-sid option during compilation,
Let PHP automatically pass the session id across pages.
2. Manually pass session IDs through URL values and hidden forms.
3. Save session_id in the form of files and databases, and manually call it during the cross-page process.
Example: A simple example of php logging out using session
Login
// You must enable the session before using the variable values stored in the session.
Session_start ();
// Use a session variable to check the logon status
If (isset ($ _ SESSION ['username']) {
Echo 'you are Logged as '. $ _ SESSION ['username'].'
';
// Click "Log Out" and go to the logOut page to Log Out.
Echo 'Log Out ('. $ _ SESSION ['username'].') ';
}
/** On the logon page, you can use the user's session, for example, $ _ SESSION ['username'],
* $ _ SESSION ['user _ id'] queries the database, so you can do a lot of things */
?>
Exit
// Even if you log out, you must start the session before accessing the session variable.
Session_start ();
// Use a session variable to check the logon status
If (isset ($ _ SESSION ['user _ id']) {
// To clear the SESSION variable, set the $ _ SESSION super global variable to an empty array
$ _ SESSION = array ();
// If a session cookie exists, delete it by setting the expiration time to the previous one hour
If (isset ($ _ COOKIE [session_name ()]) {
Setcookie (session_name (), '', time ()-3600 );
}
// Use the built-in session_destroy () function to call and cancel a session
Session_destroy ();
}
// The location header redirects the browser to another page
$ Home_url = 'login. php ';
Header ('location: '. $ home_url );
?>