v5:session:session_index
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
session:session_library [2016/01/08 22:32] – [Compression/Encryption Schemes] mnewnham | v5:session:session_index [2022/10/20 09:48] – Move adodb-session.php deprecation notice to Introduction section dregad | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Session Management ====== | ====== Session Management ====== | ||
- | < | + | ~~NOTOC~~ |
- | The original | + | < |
+ | [[v5:session: | ||
+ | [[v5:session: | ||
</ | </ | ||
+ | |||
===== Introduction ===== | ===== Introduction ===== | ||
+ | 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 | ||
- | ==== Why Session | + | * Simplified clean-up at end of session life |
+ | * Easy analysis of session data | ||
+ | * Simple session termination | ||
+ | * **//Session | ||
+ | * Encryption of session data | ||
+ | * Allows implementation of session termination callbacks | ||
+ | * Session data can be retained if used across with load balancing servers | ||
- | We store state information specific to a user or web client in session | + | ADOdb session |
- | To use session variables, call session_start() at the beginning of your web page, before your HTTP headers are sent. Then for every variable you want to keep alive for the duration of the session, call variable you want to keep alive for the duration of the session, use '' | ||
- | |||
- | The default method of storing sessions is to store it in a file. However if you have special needs such as you: | ||
- | |||
- | * Have multiple web servers that need to share session info | ||
- | * Need to do special processing of each session | ||
- | * Require notification when a session expires | ||
- | |||
- | The ADOdb session handler provides you with the above additional capabilities by storing the session information as records in a database table that can be shared across multiple servers. | ||
These records will be garbage collected based on the php.ini [session] timeout settings. You can register a notification function to notify you when the record has expired and is about to be freed by the garbage collector. | These records will be garbage collected based on the php.ini [session] timeout settings. You can register a notification function to notify you when the record has expired and is about to be freed by the garbage collector. | ||
- | An alternative to using a database backed session handler is to use 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: |
- | ===== The Improved Session Handler ===== | + | <WRAP important> |
+ | The original session management routines that use '' | ||
+ | </ | ||
- | In ADOdb 4.91, we added a new session handler, in adodb-session2.php. It features the following improvements: | ||
- | Fully supports server farms using a new database table format. | + | ===== Driver Support ===== |
- | The older database table format is obsolete. The database table must be modified to support storage of the database server time mentioned above. Also the field named DATA has been changed to SESSDATA. In some databases, DATA is a reserved word. | + | The following drivers are known to work with the adodb-session2.php file: |
+ | - mysqli | ||
+ | - pdo_mysqli (From ADOdb version | ||
+ | - postgres | ||
+ | - oci8 | ||
- | The functions '' | + | This is not an exhaustive list, if you are using the system with a different database, let us know so we can add it to the list. |
===== Usage ===== | ===== Usage ===== | ||
Line 39: | Line 45: | ||
session_start(); | session_start(); | ||
- | # | + | /* |
- | # Test session vars, the following should increment on refresh | + | * Test session vars, the following should increment on refresh |
- | # | + | */ |
+ | if (!isset($_SESSION[' | ||
+ | $_SESSION[' | ||
+ | | ||
$_SESSION[' | $_SESSION[' | ||
print "< | print "< | ||
Line 49: | Line 58: | ||
When the session is created in session_start( ), the global variable '' | When the session is created in session_start( ), the global variable '' | ||
- | The default name of the table is sessions2. | + | The default name of the table is **sessions2**. |
+ | ==== Overriding Table Name Defaults ==== | ||
<code php> | <code php> | ||
include_once " | include_once " | ||
Line 71: | Line 81: | ||
adodb-session2.php | adodb-session2.php | ||
- | adodb-cryptsession2.php | + | adodb-cryptsession2.php |
- | adodb-session-clob2.php | + | |
+ | adodb-session-clob2.php | ||
+ | | ||
==== Usage Examples ==== | ==== Usage Examples ==== | ||
Line 88: | Line 100: | ||
ADOdb_Session:: | ADOdb_Session:: | ||
- | ADOdb_session::Persist($connectMode=false); | + | ADOdb_Session::persist($connectMode=false); |
session_start(); | session_start(); | ||
</ | </ | ||
- | + | ==== DSN Support ==== | |
- | # or, using DSN support so you can set other options such as port (since 5.11) | + | using DSN support so you can set other options such as port number: |
<code php> | <code php> | ||
Line 102: | Line 114: | ||
</ | </ | ||
- | The parameter to the '' | ||
- | |||
- | $connectMode Connection Method | ||
- | true | ||
- | PConnect( ) | ||
- | |||
- | false Connect( ) | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | To use a encrypted sessions, | + | ===== Using Encrypted Sessions ===== |
+ | To use a encrypted sessions, replace the file '' | ||
<code php> | <code php> | ||
Line 124: | Line 127: | ||
ADOdb_Session:: | ADOdb_Session:: | ||
- | adodb_sess_open(false, | ||
session_start(); | session_start(); | ||
</ | </ | ||
Line 139: | Line 141: | ||
ADOdb_Session:: | ADOdb_Session:: | ||
- | adodb_sess_open(false, | ||
session_start(); | session_start(); | ||
</ | </ | ||
Line 147: | Line 148: | ||
Create this table in your database. | Create this table in your database. | ||
- | ==== MySQL ==== | + | ==== MySQL or PDO MySQL ==== |
| | ||
CREATE TABLE sessions2( | CREATE TABLE sessions2( | ||
sesskey VARCHAR( 64 ) NOT NULL DEFAULT '', | sesskey VARCHAR( 64 ) NOT NULL DEFAULT '', | ||
- | | + | |
expireref VARCHAR( 250 ) DEFAULT '', | expireref VARCHAR( 250 ) DEFAULT '', | ||
created DATETIME NOT NULL , | created DATETIME NOT NULL , | ||
Line 228: | Line 229: | ||
$user = $ADODB_SESS_CONN-> | $user = $ADODB_SESS_CONN-> | ||
- | $ADODB_SESS_CONN-> | + | $ADODB_SESS_CONN-> |
system(" | system(" | ||
} | } | ||
Line 267: | Line 268: | ||
will compress and then encrypt the record in the database. | will compress and then encrypt the record in the database. | ||
- | ===== Session Cookie Regeneration ===== | ||
- | The method '' | ||
- | ==== Usage ==== | ||
- | |||
- | <code php> | ||
- | include ' | ||
- | |||
- | session_start(); | ||
- | /* | ||
- | * Approximately every 10 page loads, reset cookie for safety. | ||
- | * This is extremely simplistic example, better | ||
- | * to regenerate only when the user logs in or changes | ||
- | * user privilege levels. | ||
- | */ | ||
- | if ((rand()%10) == 0) | ||
- | adodb_session_regenerate_id(); | ||
- | </ | ||
- | |||
- | This function calls '' | ||
- | |||
- | ===== Vacuum/ | ||
- | |||
- | During session garbage collection, if postgresql is detected, ADOdb can be set to run VACUUM. If mysql is detected, then optimize database could be called.You can turn this on or off using: | ||
- | <code php> | ||
- | $turnOn = true; # or false | ||
- | ADODB_Session:: | ||
- | </ | ||
- | The default is optimization is disabled. | ||
- | ===== Backwards | + | ===== Backwards |
The older method of connecting to ADOdb using global variables is now deprecated, and **will be removed** in ADOdb version 6.0: | The older method of connecting to ADOdb using global variables is now deprecated, and **will be removed** in ADOdb version 6.0: | ||
Line 306: | Line 279: | ||
$ADODB_SESSION_USER =' | $ADODB_SESSION_USER =' | ||
$ADODB_SESSION_PWD =' | $ADODB_SESSION_PWD =' | ||
- | $ADODB_SESSION_DB ='phplens'; | + | $ADODB_SESSION_DB ='employees'; |
include ' | include ' |
v5/session/session_index.txt · Last modified: 2023/04/08 18:08 by dregad