ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:session:session_index

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:session:session_index [2018/07/24 01:07] – [Introduction] mnewnhamv5:session:session_index [2023/04/08 18:08] (current) – Add WRAPs for notes dregad
Line 1: Line 1:
 ====== Session Management ====== ====== Session Management ======
-~~NOTOC~~ 
 <WRAP right box> <WRAP right box>
 [[v5:session:Index]]\\ [[v5:session:Index]]\\
Line 9: Line 8:
 ADOdb session management extends the standard functionality of PHP sessions, by allowing the normal session data seen to be stored in a database itself. There are numerous ways that this method enhances the default behavior ADOdb session management extends the standard functionality of PHP sessions, by allowing the normal session data seen to be stored in a database itself. There are numerous ways that this method enhances the default behavior
  
-  * Simplified clean-up at end =of session life+  * Simplified clean-up at end of session life
   * Easy analysis of session data   * Easy analysis of session data
   * Simple session termination   * Simple session termination
Line 23: Line 22:
  
 An alternative to using a database backed session handler is to use [[v5:userguide:memcached]]. This is a distributed memory based caching system suitable for storing session information. An alternative to using a database backed session handler is to use [[v5:userguide:memcached]]. This is a distributed memory based caching system suitable for storing session information.
 +
 +<WRAP important>
 +The original session management routines that use ''adodb-session.inc.php'' are deprecated as of ADOdb version 5.20, and will be removed in ADOdb Version 6.0.0. For information on upgrading from the original version, see [[v5:session:version1|Here]]
 +</WRAP>
 +
  
 ===== Driver Support ===== ===== Driver Support =====
Line 109: Line 113:
 </code> </code>
  
-<WRAP important> +
-The original session management routines that use ''adodb-session.inc.php'' are deprecated as of ADOdb version 5.20, and will be removed in ADOdb Version 6.0.0. For information on upgrading from the original version, see [[v5:session:version1|Here]] +
-</WRAP>+
 ===== Using Encrypted Sessions ===== ===== Using Encrypted Sessions =====
 To use a encrypted sessions, replace the file ''adodb-session2.php'' with ''adodb-cryptsession2.php'': To use a encrypted sessions, replace the file ''adodb-session2.php'' with ''adodb-cryptsession2.php'':
Line 146: Line 148:
  
 ==== MySQL or PDO MySQL ==== ==== MySQL or PDO MySQL ====
-   + 
-  CREATE TABLE sessions2( +<code> 
-   sesskey VARCHAR( 64 ) NOT NULL DEFAULT '', +CREATE TABLE sessions2 ( 
-   expiry DATETIME NOT NULL , +  sesskey VARCHAR( 64 ) COLLATE utf8mb4_bin NOT NULL DEFAULT '', 
-   expireref VARCHAR( 250 ) DEFAULT '', +  expiry DATETIME NOT NULL , 
-   created DATETIME NOT NULL , +  expireref VARCHAR( 250 ) DEFAULT '', 
-   modified DATETIME NOT NULL , +  created DATETIME NOT NULL , 
-   sessdata LONGTEXT, +  modified DATETIME NOT NULL , 
-   PRIMARY KEY ( sesskey ) , +  sessdata LONGTEXT, 
-   INDEX sess2_expiry( expiry ), +  PRIMARY KEY ( sesskey ) , 
-   INDEX sess2_expireref( expireref ) +  INDEX sess2_expiry( expiry ), 
-  )+  INDEX sess2_expireref( expireref ) 
 +) 
 +</code> 
 + 
 +<WRAP info> 
 +When [[https://www.php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character|session.sid_bits_per_character]] php.ini setting is set to 6, the //Session ID// can contain both upper and lowercase letters.  
 +Collisions could occur in this case, due to MySQL performing case-insensitive searches by default.  
 +To avoid that, the //sesskey// column should use binary (or a case-sensitive) collation. 
 +</WRAP> 
  
 ==== PostgreSQL ==== ==== PostgreSQL ====
Line 195: Line 206:
 ===== Notifications ===== ===== Notifications =====
  
-You can receive notification when your session is cleaned up by the session garbage collector or when you call session_destroy().+You can receive notification when your session is cleaned up by the session garbage collector or when you call //session_destroy()//.
  
-PHP's session extension will automatically run a special garbage collection function based on your php.ini session.cookie_lifetime and session.gc_probability settings. This will in turn call adodb's garbage collection function, which can be setup to do notification.+PHP's session extension will automatically run a special garbage collection function based on your php.ini session.cookie_lifetime and session.gc_probability settings. This will in turn call ADOdb's garbage collection function, which can be setup to perform notification.
  
- PHP Session --> ADOdb Session  --> Find all recs  --> Send          --> Delete queued +  PHP Session --> ADOdb Session --> Find all recs --> Send         --> Delete 
- GC Function     GC Function        to be deleted      notification      records +  GC Function     GC Function       to be deleted     notification     queued 
- executed at     called by                             for all recs +  executed at     called by                           for all recs     records 
- random time     Session Extension                     queued for deletion+  random time     Session                             queued for 
 +                  Extension                           deletion
  
 When a session is created, we need to store a value in the session record (in the EXPIREREF field), typically the userid of the session. Later when the session has expired, just before the record is deleted, we reload the EXPIREREF field and call the notification function with the value of EXPIREREF, which is the userid of the person being logged off. When a session is created, we need to store a value in the session record (in the EXPIREREF field), typically the userid of the session. Later when the session has expired, just before the record is deleted, we reload the EXPIREREF field and call the notification function with the value of EXPIREREF, which is the userid of the person being logged off.
Line 229: Line 241:
  system("rm /work/tmpfiles/$expireref/*");  system("rm /work/tmpfiles/$expireref/*");
 } }
-</code>    +</code> 
-NOTE 1: If you have register_globals disabled in php.ini, then you will have to manually set the EXPIREREFe.g.+ 
 +<WRAP info> 
 +EXPIREREF must be set manually, e.g. 
  
 <code php> <code php>
Line 237: Line 251:
 </code> </code>
  
-NOTE 2: If you want to change the EXPIREREF after the session record has been created, you will need to modify any session variable to force a database record update.+In older versions of ADOdb this could be achieved automatically through the use of register_globals, but this feature has been [[https://php-legacy-docs.zend.com/manual/php5/en/security.globals|removed in PHP 5.4 for security reasons]]. 
 +</WRAP>
  
 +<WRAP info>
 +If you want to change the EXPIREREF after the session record has been created, you will need to modify any session variable to force a database record update.
 +</WRAP>
 ===== Neat Notification Tricks =====  ===== Neat Notification Tricks ===== 
  
Line 276: Line 294:
 $ADODB_SESSION_USER ='root'; $ADODB_SESSION_USER ='root';
 $ADODB_SESSION_PWD ='abc'; $ADODB_SESSION_PWD ='abc';
-$ADODB_SESSION_DB ='phplens';+$ADODB_SESSION_DB ='employees';
  
 include 'adodb/adodb-session.php'; include 'adodb/adodb-session.php';
v5/session/session_index.1532387239.txt.gz · Last modified: 2018/07/24 01:07 by mnewnham