Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:25:42+00:00 2026-05-27T17:25:42+00:00

I have a few a few question about php sessions: Since the default value

  • 0

I have a few a few question about php sessions:

  1. Since the default value for session.gc_maxlifetime is 24 mins then that means any session file that isn’t modified for 24 mins will be deleted and the session will expire automatically.

  2. If I use session_destroy() in my code the session will be unset, but the session file itself won’t be deleted until 24 mins passes since it was last modified.

  3. The only way to extend the session’s life time (more than 24 mins) is to extend session.gc_maxlifetime to a bigger value.

Are all these correct or did I get something wrong about it?

Also if I store my sessions in a database (using session_set_save_handler()) will all these rules apply to them ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:25:43+00:00Added an answer on May 27, 2026 at 5:25 pm
    1. Almost. The file (session) will not be deleted immediately, that is determined by session.gc_probability and session.gc_divisor.

    2. No, the session will be expired, but the deletion of the session file is determined as stated in previous point

    3. That is correct ordinarily, but if you were to implement your own session handler, you could alter the behavior of session expiration even in such a way that session.gc_maxlifetime is ignored

    Storing session in db should not alter those rules, but could stretch them a little, if you wanted to.

    edit:

    This is roughly how you can register your own session handler (handler being a class) and then do whatever you want with it

    First, suppose we have a class, that is going to be handling sessions for our application.

    class MySession {
      function open($save_path, $session_name) {
      }
    
      function close() {
      }
    
      function read($id) {
      }
    
      function write($id, $sess_data) {
      }
    
      function destroy($id) {
      }
    
      function gc($maxlifetime) {
      }
    }
    

    To register the handler in php, you only need to call session_set_save_handler function, like this in our case:

    // register the session handler
    $sess = new MySession();
    session_set_save_handler(array($sess, 'open'),
                         array($sess, 'close'),
                         array($sess, 'read'),
                         array($sess, 'write'),
                         array($sess, 'destroy'),
                         array($sess, 'gc'));
    

    Note that there are actually better ways to register the handler itself, you could even do this in the constructor of your class, or in numerous other ways. But I assume that is not the point here.

    What is important is the fact that although PHP gives you the needed variables corresponding to standard behavior of it’s session management mechanism, you don’t have to respect it (not that I would recommend that).

    To answer a comment below, to ignore the maxlifetime parameter, you ignore that in your gc method and use whatever you deem necessary/right, for example (using db pseudo code):

    function gc($maxlifetime) { 
      $sql = "DELETE * FROM MySession WHERE lastAccess < NOW()-3600";
      // execute the query, say I have PDO instance in $dbh variable
      $dbh->execute($sql);
    }
    

    Voila, you just completely circumvented PHP session settings by doing it by yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I had a few question about OO and classes in PHP here but
I have a few questions about security using PHP, I dont want to use
I have a few questions about sessions and login/logout systems. In my system, first
I have asked a few question lately about the use of the singleton and
I have a few questions about data synchronization. The architecture does not seem to
I have a few questions about Xcode and interaction with GCC 4.2.1: It doesn't
I have a few questions about this after reading the iPhone documentation on it:
I have a few questions about cross-page posting in ASP.NET: What is cross-page posting
I have a few questions about Core Location. 1) Should the user refuse permission
I have a few quick questions about the Microsoft Detours Library. I have used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.