Php session loss (cross-page transfer is not allowed) solution

Source: Internet
Author: User
Tags define session php session
In general, the SESSION is lost in the following aspects: 1. cookie2 is disabled on the client, cookie3 and php cannot be accessed by the browser. session in ini. use_trans_sid = 0 or the & amp; ndash; enable-trans-sid option Session is not enabled during compilation and stored on the server side (the default mode is file... "> <LINKhref =

 

In general, SESSION loss involves the following:
1. cookie disabled on the client
2. the browser cannot access cookies.
3. in php. ini, session. use_trans_sid = 0 or compile
The-enable-trans-sid option is not enabled.

The Session is stored on the server side (stored as a file by default). the user's file is obtained based on the session id provided by the client,
Get the value of the variable. the session id can use the Cookie of the client or Query_String of the Http1.1 protocol.
(That is, the "?" of the Accessed URL And then the server reads the Session directory ....... That is to say,
Session id is used to obtain the id card of the session variable stored in the service. When the code session_start (); is running,
A session file is generated on the server, and a unique session id is generated accordingly,
Define session variables to be stored in the generated session file in a certain form. By session id,
You can retrieve the defined variables. To use the session, you must execute session_start ();
A session file is generated, and the corresponding session id is generated,
Using this session id cannot retrieve the variables in the first session file mentioned above,
Because this session id is not the "key" to open it ". In session_start ();
The code session_id ($ session id) is added before. no new session file is generated,
Directly read the session file corresponding to this id.

By default, the session in PHP uses the Cookie of the client to save the session id,
Therefore, when the client cookie is faulty, the session will be affected. Note that:
The session does not have to rely on cookies, which is a bit more advanced than the cookie.
When the client's Cookie is disabled or has problems, PHP automatically attaches the session id to the URL,
In this way, the session variable can be used across pages through the session id. However, such attachment also has certain conditions,
That is, "session. use_trans_sid = 1 in php. ini or the-enable-trans-sid option is enabled during compilation ".

Now that we understand the above principles, there are three main ways to discard the cookie session:
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.

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.