* */ /** * * For enable encryption you must define the constant DALMP_SQLITE_ENC_KEY * that constan will have the key used for encrypting / decrypting. * * existing databases will need to be recreated, since now the full database will be encrypted * in case of an error simple delete your old database and let DALMP re-create it automatically * */ define('DALMP_SQLITE_ENC_KEY', 'my sqlite key'); /** * thats all, now your sqlite3 database will be encrypted. */ define('DALMP_SESSIONS_SQLITE_DB', '/tmp/sessions.db'); $sessions = new DALMP_Sessions(); /** * access this script from a browser for avoiding complains * later check for the dalmp_sessions.db and try to read it * from the comand line you can test the encryption by doing strings dalmp_sessions.db ?:z{ Eyq ... */ $_SESSION['test'] = 1 + @$_SESSION['test']; echo $_SESSION['test'] . ' - ' . session_id(); echo DALMP::isCli(1); # ----------------------------------------------------------------------------------------------------------------- echo PHP_EOL, str_repeat('-', 80), PHP_EOL, 'Time: ', $timer->getPageLoadTime(), ' - Memory: ', $timer->getMemoryUsage(1), PHP_EOL, str_repeat('-', 80), PHP_EOL;
<?php require_once '../mplt.php'; $timer = new mplt(); require_once '../dalmp.php'; # ----------------------------------------------------------------------------------------------------------------- $db = new DALMP('utf8://dalmp:password@192.168.1.40:3306/dalmptest'); /** * -- ---------------------------- -- Table structure for `dalmp_sessions` -- ---------------------------- CREATE TABLE IF NOT EXISTS `dalmp_sessions` ( `sid` varchar(40) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '', `expiry` int(11) unsigned NOT NULL DEFAULT '0', `data` longtext CHARACTER SET utf8 COLLATE utf8_unicode_ci, `ref` varchar(255) DEFAULT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`sid`), KEY `index` (`ref`,`sid`,`expiry`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; * */ /** * to store sessions on mysql you need to pass the $db DALMP object if not defaults to sqlite */ $sessions = new DALMP_Sessions($db); $GLOBALS['UID'] = 1; if (mt_rand() % 10 == 0) { $sessions->regenerate_id(4); }
<?php require_once '../mplt.php'; $timer = new mplt(); require_once '../dalmp.php'; # ----------------------------------------------------------------------------------------------------------------- $db = new DALMP('utf8://dalmp:password@192.168.1.40:3306/dalmptest'); /** * name of the REF field global var */ define('DALMP_SESSIONS_REF', 'UID'); /** * to store sessions on mysql you need to pass the $db DALMP object */ $sessions = new DALMP_Sessions($db); /** * here you can declare the user ID so later check how many users are logged in or also avoid users to login twice */ $uid = 1; $GLOBALS['UID'] = $uid; if (mt_rand() % 10 == 0) { $sessions->regenerate_id(4); // always after your $GLOBALS } /** * get the REF stored on DB or Cache */ $rs = $sessions->getSessionRef($uid); echo '<pre>'; print_r($rs); echo '</pre>';