Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Wednesday, October 14, 2009

Making a whos online script with Zend_Session_SaveHandler_DbTable

1] fetch rows from zend_session table where modifiedtime > time()-900
2] unserialize the data column using this function

function DecodeSession($sess_string)
{
// save current session data
// and flush $_SESSION array
$old = $_SESSION;
$_SESSION = array();

// try to decode passed string
$ret = session_decode($sess_string);
if (!$ret) {
// if passed string is not session data,
// retrieve saved (old) session data
// and return false
$_SESSION = array();
$_SESSION = $old;

return false;
}

// save decoded session data to sess_array
// and flush $_SESSION array
$sess_array = $_SESSION;
$_SESSION = array();

// restore old session data
$_SESSION = $old;

// return decoded session data
return $sess_array;
}

3] print out the username which should be stored in the session data, it'll look
something like
echo $session['data']['Namespace']['user']['username'];

Wednesday, September 10, 2008

CakePHP 1.19 Test Suite testing with Session Component

Hello, you might be having a tough time doing some integration testing on your controllers which use the Session component. Here are is an example to help you get started:


class Foo_ControllerTest extends UnitTestCase
{
function test1()
{

$usersController = &new UsersController();
$usersController->_initComponents();
$usersController->constructClasses();
$this->assertNotNull($usersController->Session);
$usersController->Session->_checkValid();

}
}


This creates the model + components in your controller. The sessions should be working normally now.

Take at look at this to see how they did unit testing on the Session component itself for more ideas (https://trac.cakephp.org/browser/branches/1.2.x.x/cake/tests/cases/libs/session.test.php?rev=7246).