Handling sessions without Apache sessions
You are all familiar that Apache sessions are slow and sometimes insecure. In this text I will try to implement way of handling sessions with all Doo::cache mechanisms that are available in DooPhp.
So our sessions will be stored in some of the cache mechanisms. First we will start with writting our session class that will start and end session, we will save it in protected/class folder.
Here is our Session.class
<?php
/**
* Session handler
*
* @author Milos Kovacki <kovacki@gmail.com>
* @copyright Milos Kovacki 2010 <kovacki@gmail.com>
*/
class Session
{
public static $_sessionId = NULL;
public static $session = array();
/**
* Start session
*/
public static function startSession() {
self::$_sessionId = (isset($_COOKIE['session_id']) ? $_COOKIE['session_id'] : NULL);
if ((!self::$_sessionId)||(!(self::$session=Doo::cache(Doo::conf()->sessionCacheType)->get('session_'.self::$_sessionId)))) {
// Create new session
self::$_sessionId = md5($_SERVER['REMOTE_ADDR'] . time() . rand(0,128));
self::$session['ip'] = $_SERVER['REMOTE_ADDR'];
self::$session['created'] = time();
}
setcookie('session_id', self::$_sessionId, (time()+3600*24*90), '/');
}
/**
* End session
*/
public static function endSession() {
$sessionStored = Doo::cache(Doo::conf()->sessionCacheType)->set('session_'.self::$_sessionId, self::$session);
}
}
You all noticed variable Doo::conf()->sessionCacheType so we need to add it in our protected/config/common.conf edit it and add:
$config['sessionCacheType'] = 'apc';
You can choose any type that is supported in Doo::cache, now we will edit our index.php, here is my bootstrap:
<?php
/**
* BOOTSTRAP
*/
//ini_set('display_errors', 1);
include './protected/config/common.conf.php';
include './protected/config/routes.conf.php';
include $config['BASE_PATH'].'Doo.php';
More »

