note 84082 deleted from function.session-set-save-handler by danbrown

From: Date: Sun, 23 Jan 2011 16:14:39 +0000
Subject: note 84082 deleted from function.session-set-save-handler by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176028@lists.php.net to get a copy of this message
Note Submitter: andreas dot beder at gmx dot at ---- in reply to shaun freeman mdb2 session handler: i just tried your code and want to correct some lines. at first the database, i wonder why there is a session_id column when no line uses it ?? the second one: the return value of the read method is a database resource so no session variable will be set. database structure: CREATE TABLE IF NOT EXISTS sessions ( session varchar(255) character set utf8 collate utf8_bin NOT NULL, session_expires int(10) unsigned NOT NULL default '0', session_data mediumtext collate utf8_unicode_ci, KEY session (session) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; you could replace the read method with: <? function read($sessID) { global $php_errormsg; // fetch session-data $query = " SELECT session_data FROM sessions WHERE session = '$sessID' AND session_expires > ".time(); $result = $this->mdb2->query($query); // return data or an empty string at failure if (MDB2::isError($result)) { $php_errormsg .= $result->getMessage(); $php_errormsg .= $result->getDebugInfo (); return false; } list($value)=@$result->fetchrow(); return $value; } ?> it also took me a while to figure out what parameter i have to give the session class. <? ini_set("session.save_handler", "user"); require_once 'MDB2.php'; include("sessions.php"); // here should be your database class $dsn = array( 'phptype' => $cfg[db_type], 'username' => $cfg[db_user], 'password' => $cfg[db_pass], 'hostspec' => $cfg[db_host], 'database' => $cfg[db], ); $options = array( 'debug' => 2, 'portability' => MDB2_PORTABILITY_ALL, ); $db =& MDB2::connect($dsn, $options); if (PEAR::isError($db)) { die($db->getMessage()); } $session=new Session($dsn); session_start(); echo $_SESSION["login"]=$_SESSION["login"]+1; ?>

« previous php.notes (#176028) next »