10.20
php
saved
CakeFreak
Note
Library to extend CakeSession library in order to use the SMF forum session table (it misses the *id* column)
Read this thread for more infos
http://groups.google.com/group/cake-php/browse_frm/thread/e44d0a4b957f3bf0
Library to extend CakeSession library in order to use the SMF forum session table (it misses the *id* column)
Read this thread for more infos
http://groups.google.com/group/cake-php/browse_frm/thread/e44d0a4b957f3bf0
- <?php
- /**
- * Session class for using the Session Table of the SMF forum.
- * This is needed because the SMF forum does not have a primary
- * column called *id*, and then we want CakePHP to use a primary column
- * called *session_id*
- *
- * CREATE TABLE `smf_sessions` (
- * `session_id` char(32) NOT NULL default '',
- * `last_update` int(10) unsigned default NULL,
- * `data` text,
- * `expires` int(11) default NULL,
- * PRIMARY KEY (`session_id`)
- * ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- *
- * Cake 1.2
- *
- * Read this Post for further instructions:
- * http://groups.google.com/group/cake-php/browse_frm/thread/e44d0a4b957f3bf0
- *
- *
- * @author Daniel Vecchiato (aka CakeFreak)
- * @link http://www.4webby.com/
- * @package cake
- * @subpackage cake.cake.libs
- * @since CakePHP(tm) v .0.10.0.1222
- * @version 1.0
- * @lastmodified 2007-10-20
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- */
- /**
- * Database name for cake sessions.
- *
- */
- uses('set');
- /**
- * Session class for Cake.
- *
- * Cake abstracts the handling of sessions. There are several convenient methods to access session information.
- * This class is the implementation of those methods. They are mostly used by the Session Component.
- *
- * @package cake
- * @subpackage cake.cake.libs
- */
- require_once('session_cake.php');
- class SmfSession extends CakeOriginalSession {
- /**
- * Constructor.
- *
- * @param string $base The base path for the Session
- * @param boolean $start Should session be started right now
- * @access public
- */
- function __construct($base = null, $start = true) {
- //Set the name of the primary column used by SMF the session DB table
- }
- parent::__construct();
- }
- /**
- * Method used to read from a database session.
- *
- * @param mixed $key The key of the value to read
- * @return mixed The value of the key or false if it does not exist
- * @access private
- */
- function __read($key) {
- $db =& ConnectionManager::getDataSource('default');
- $table = $db->fullTableName(CAKE_SESSION_TABLE, false);
- $row = $db->query("SELECT " . $db->name($table.'.data') . " FROM " . $db->name($table) . " WHERE " . $db->name($table.'.'.SESS_COL_ID) . " = " . $db->value($key), false);
- $table = 0;
- }
- if ($row && $row[0][$table]['data']) {
- return $row[0][$table]['data'];
- } else {
- return false;
- }
- }
- /**
- * Helper function called on write for database sessions.
- *
- * @param mixed $key The name of the var
- * @param mixed $value The value of the var
- * @return boolean Success
- * @access private
- */
- function __write($key, $value) {
- $db =& ConnectionManager::getDataSource('default');
- $table = $db->fullTableName(CAKE_SESSION_TABLE);
- switch(CAKE_SECURITY) {
- case 'high':
- $factor = 10;
- break;
- case 'medium':
- $factor = 100;
- break;
- case 'low':
- $factor = 300;
- break;
- default:
- $factor = 10;
- break;
- }
- $row = $db->query("SELECT COUNT(".SESS_COL_ID.") AS count FROM " . $db->name($table) . " WHERE "
- . $db->name(SESS_COL_ID) . " = "
- . $db->value($key), false);
- if ($row[0][0]['count'] > 0) {
- $db->execute("UPDATE " . $db->name($table) . " SET " . $db->name('data') . " = "
- . $db->value($value) . ", " . $db->name('expires') . " = "
- . $db->value($expires) . " WHERE " . $db->name(SESS_COL_ID) . " = "
- . $db->value($key));
- } else {
- $db->execute("INSERT INTO " . $db->name($table) . " (" . $db->name('data') . ","
- . $db->name('expires') . "," . $db->name(SESS_COL_ID)
- . ") VALUES (" . $db->value($value) . ", " . $db->value($expires) . ", "
- . $db->value($key) . ")");
- }
- return true;
- }
- /**
- * Method called on the destruction of a database session.
- *
- * @param int $key Key that uniquely identifies session in database
- * @return boolean Success
- * @access private
- */
- function __destroy($key) {
- $db =& ConnectionManager::getDataSource('default');
- $table = $db->fullTableName(CAKE_SESSION_TABLE);
- $db->execute("DELETE FROM " . $db->name($table) . " WHERE " . $db->name($table.'.'.SESS_COL_ID) . " = " . $db->value($key, 'integer'));
- return true;
- }
- }
- ?>
Parsed in 0.181 seconds, using GeSHi 1.0.7.14