note 84082 added to function.session-set-save-handler
| From: | andreas dot beder at gmx dot at | Date: | Thu, 26 Jun 2008 19:46:50 +0000 |
| Subject: | note 84082 added to function.session-set-save-handler | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140852@lists.php.net to get a copy of this message | ||
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;
?>
----
Server IP: 81.223.48.75
Probable Submitter: 78.41.112.52
----
Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php
Edit -- https://master.php.net/note/edit/84082
Del: integrated -- https://master.php.net/note/delete/84082/integrated
Del: useless -- https://master.php.net/note/delete/84082/useless
Del: bad code -- https://master.php.net/note/delete/84082/bad+code
Del: spam -- https://master.php.net/note/delete/84082/spam
Del: non-english -- https://master.php.net/note/delete/84082/non-english
Del: in docs -- https://master.php.net/note/delete/84082/in+docs
Del: other reasons-- https://master.php.net/note/delete/84082
Reject -- https://master.php.net/note/reject/84082
Search -- https://master.php.net/manage/user-notes.php