Phpsession cannot be saved solution-PHP source code

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

Related Article

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.