Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 171 | All time: 8,830 This week: 660 |
Version | License | PHP version | Categories | |||
pgsessions 1.0.0 | MIT/X Consortium ... | 5 | PHP 5, User Management |
Description | Author | |||||||||||||||||||||||
This class implements a session handler that store PHP sessions in PostgreSQL table using PDO. Innovation Award |
|
> Disclaimer: Storing sessions in PHP via files(default) and other caching systems like Memcache / memcached / Redis is definitely faster but there was this use case where I had to use RDBMS for storing sessions and hence this. Use this only when it is a strict requirement to save sessions in a relational database
Create "sessions" database as provided below.
CREATE TABLE "sessions" ( "id" TEXT NOT NULL UNIQUE, "last_updated" BIGINT NOT NULL, "expiry" bigint NOT NULL, "data" TEXT NOT NULL); CREATE INDEX "valid_sessions" ON "sessions"("id"); CREATE INDEX "nonexpired_sessions" ON "sessions"("id","expiry");
Steps to use:
Define SESSION_DURATION constants to set session expiry.
SESSION_DURATION -> Expiry of sessions in number of seconds.
require_once 'PGSessions.php';
$pdo_connection = new PDO(...);
use \PGSessions\PGSessions;
$sessions_handler = new PGSessions($pdo_connection);
session_set_save_handler($sessions_handler, true);
session_name('MySessionName');
session_start();
session_regenerate_id(true);
$_SESSION['something'] = 'foo';
$_SESSION['something_else'] = 'bar';
echo session_id(),'<br/>',$_SESSION['something'],'<br />',$_SESSION['something_else'] ;
/*
Rest of your script
.
.
.
.
.
.
.
.
.
.
Before ending your script
*/
session_write_close();
//Note that session_write_close is not REQUIRED to be called on each page since we register_shutdown_function=true (second parameter = true in session_set_save_handler).
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.