In most forums, you can select the expiration time when logging on, such as one week or one month. In this case, you can set the logon expiration time through Cookie. The Session expiration time can be set in the following ways: in most forums, you can select the expiration time during logon, such as one week or one month. In this case, you can set the logon expiration time through Cookie. The Session expiration time can be set in the following ways:
1. the client does not disable cookies.
(1) useSession_set_cookie_params ()Set the Session expiration time. This function is used to set the expiration time of the Session with the Cookie. If you want to invalidate the Session after one minute, the sample code is as follows:
Note: session_set_cookie_params () must be called before session_start.
Note: We do not recommend using this function, which may cause problems in some browsers. Therefore, you can set the expiration time manually.
(2) useSetcookie ()The function can set the expiration time for the Session. to invalidate the Session after one minute, the code example is as follows:
Note: In the preceding code setcookie () function, session_name is the name of the Session, and session_id is the identifier of the client user, because session_id is a random and unique name, therefore, the Session is relatively secure. The expiration time is the same as the Cookie's expiration time. the last parameter is an optional parameter, which is the path for storing cookies.
2. the client disables cookies.
When the client disables cookies, the Session page transmission will fail. you can think of the client as a large supermarket chain. if you have applied for a membership card in one of the supermarkets, but there is no internet connection between supermarkets, so the membership card can only be used in the supermarket. There are several ways to solve this problem:
(1) remind users to enable cookies before Login. this is the practice of many forums.
(2) set session. use_trans_sid = 1 in the php. ini file, or enable the-enable-trans-sid option during compilation, so that PHP will automatically pass session_id across pages.
(3) use the GET method to hide the form and pass session_id.
(4) manually call the session_id stored in the file or database during inter-page transfer.
The above 2nd methods are not described in detail, because users cannot modify the php. ini file on the server. In method 3rd, we cannot use cookies to set the expiration time, but the logon status remains unchanged. 4th is also the most important one. when developing enterprise-level websites
The session file slows down the server and can be used. Here we will introduce 3rd methodsGETThe sample code is as follows:
Note: After a Session request is sent to this page, a session_id will be generated. If Cookie is disabled, the session_id cannot be passed. a new session_id will be generated on the next page of the request, this causes the session to fail to pass between pages.
The above is a detailed explanation of session time settings in php. For more information, see other related articles in the first PHP community!