1. Go to this page and download the library: Download voku/session2db library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
voku / session2db example snippets
//
// simple (dirty) example
//
use voku\db\DB;
use voku\helper\Session2DB;
DB::getInstance('hostname', 'username', 'password', 'database');
new Session2DB();
// from now on, use sessions as you would normally
// this is why it is called a "drop-in replacement" :)
$_SESSION['foo'] = 'bar';
//
// extended example
//
use voku\db\DB;
use voku\helper\DbWrapper4Session;
use voku\helper\Session2DB;
// include autoloader
, // e.g. user_1
'password', // e.g. ******
'database', // e.g. db_1
'port', // e.g. 3306
'charset', // e.g. utf8mb4
true, // e.g. true|false (exit_on_error)
true, // e.g. true|false (echo_on_error)
'', // e.g. 'framework\Logger' (logger_class_name)
'' // e.g. 'DEBUG' (logger_level)
);
// you can also use you own database implementation via the "Db4Session"-interface,
// take a look at the "DbWrapper4Session"-class for a example
$db_wrapper = new DbWrapper4Session($db);
// initialize "Session to DB"
new Session2DB(
'add_your_own_security_code_here', // security_code
0, // session_lifetime
false, // lock_to_user_agent
false, // lock_to_ip
1, // gc_probability
1000, // gc_divisor
'session_data', // table_name
60, // lock_timeout
$db_wrapper, // db (must implement the "Db4Session"-interface)
true // start_session (start the session-handling automatically, otherwise you need to use session2db->start() afterwards)
);
// from now on, use sessions as you would normally
// this is why it is called a "drop-in replacement" :)
$_SESSION['foo'] = 'bar';
// data is in the database!
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.