Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Almost. The file (session) will not be deleted immediately, that is determined by <strong>session.gc_probability</strong> and <strong>session.gc_divisor</strong>.</p></li> <li><p>No, the session will be expired, but the deletion of the session file is determined as stated in previous point</p></li> <li><p>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</p></li> </ol> <p>Storing session in db should not alter those rules, but could stretch them a little, if you wanted to.</p> <p><strong>edit:</strong></p> <p>This is roughly how you can register your own session handler (handler being a class) and then do whatever you want with it</p> <p>First, suppose we have a class, that is going to be handling sessions for our application.</p> <pre><code>class MySession { function open($save_path, $session_name) { } function close() { } function read($id) { } function write($id, $sess_data) { } function destroy($id) { } function gc($maxlifetime) { } } </code></pre> <p>To register the handler in php, you only need to call <code>session_set_save_handler</code> function, like this in our case: </p> <pre><code>// 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')); </code></pre> <p>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.</p> <p>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).</p> <p>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):</p> <pre><code>function gc($maxlifetime) { $sql = "DELETE * FROM MySession WHERE lastAccess &lt; NOW()-3600"; // execute the query, say I have PDO instance in $dbh variable $dbh-&gt;execute($sql); } </code></pre> <p>Voila, you just completely circumvented PHP session settings by doing it by yourself.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload