How can the expiration time of a session be set in PHP?

To set the expiration time of a session, you can use the function session_set_cookie_params() to set the cookie parameters of the session, including the expiration time. The specific steps are as follows:

  1. Set the cookie parameters for the session using the session_set_cookie_params() function. This function takes 4 parameters, which are expiration time (in seconds), path, domain, and secure flag. For example, to set the session expiration time to 30 minutes:
  2. Set the cookie parameters for a session to expire in 30 minutes.
  3. Start a session:
  4. Initiate a new session.

In this way, the expiration time of the session will be set to 30 minutes. The session will automatically expire if the user does not perform any actions within 30 minutes.

bannerAds