I’m getting the following errors on my site.
Warning: get_class() expects parameter 1 to be object, null given in /users/venise/www/templates/ja_sanidineii_light/ja_menus/Base.class.php on line 50
on the home page.
Base.class.php =
[code]<?php
/*------------------------------------------------------------------------
JA Sanidine II for Joomla 1.5 - Version 1.0 - Licence Owner JA98631
------------------------------------------------------------------------
Copyright © 2004-2008 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
@license - Copyrighted Commercial Software
Author: J.O.O.M Solutions Co., Ltd
Websites: http://www.joomlart.com - http://www.joomlancers.com
This file may not be redistributed in whole or significant part.
-------------------------------------------------------------------------*/
defined( ‘_VALID_MOS’ ) or defined(’_JEXEC’) or die(‘Restricted access’);
if (!defined (’_JA_BASE_MENU_CLASS’)) {
define (’_JA_BASE_MENU_CLASS’, 1);
class JA_Base{
var $_params = null;
var $children = null;
var $open = null;
var $items = null;
var $Itemid = 0;
var $showSeparatedSub = false;
function JA_Base( &$params ){
global $Itemid;
$this->_params = $params;
$this->Itemid = $Itemid;
$this->loadMenu();
}
function loadMenu(){
$this->loadMenu_15();
}
function createParameterObject($param, $path='', $type='menu') {
return new JParameter($param, $path);
}
function getPageTitle ($params) {
return $params->get ('page_title');
}
function loadMenu_15(){
$menu = @JMenu :: getInstance();
if(strtolower(get_class($menu)) == 'jexception') {
$menu = @JMenu :: getInstance('site');
}
$user =& JFactory::getUser();
$children = array ();
// Get Menu Items
$items = &JSite::getMenu();
$rows = $items->getItems('menutype', $this->getParam('menutype'));
// first pass - collect children
$cacheIndex = array();
$this->items = array();
foreach ($rows as $index => $v) {
if ($v->access <= $user->get('aid',0)) {
$pt = $v->parent;
$list = @ $children[$pt] ? $children[$pt] : array ();
switch ($v->type)
{
case 'url' :
if ((strpos($v->link, 'index.php?') !== false) && (strpos($v->link, 'Itemid=') === false)) {
$v->url = $v->link.'&Itemid='.$v->id;
} else {
$v->url = $v->link;
}
break;
default :
$router = JSite::getRouter();
$v->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$v->id : $v->link.'&Itemid='.$v->id;
break;
}
// Handle SSL links
$iParams = $this->createParameterObject($v->params);
$iSecure = $iParams->def('secure', 0);
if ($v->home == 1) {
$v->url = JURI::base();
} elseif (strcasecmp(substr($v->url, 0, 4), 'http') && (strpos($v->link, 'index.php?') !== false)) {
$v->url = JRoute::_($v->url, true, $iSecure);
} else {
$v->url = str_replace('&', '&', $v->url);
}
$v->_idx = count($list);
array_push($list, $v);
$children[$pt] = $list;
}
$cacheIndex[$v->id] = $index;
$this->items[$v->id] = $v;
}
$this->children = $children;
// second pass - collect 'open' menus
$open = array (
$this->Itemid
);
$count = 20; // maximum levels - to prevent runaway loop
$id = $this->Itemid;
while (-- $count)
{
if (isset($cacheIndex[$id])) {
$index = $cacheIndex[$id];
if (isset ($rows[$index]) && $rows[$index]->parent > 0) {
$id = $rows[$index]->parent;
$open[] = $id;
} else {
break;
}
}
}
$this->open = $open;
// $this->items = $rows;
}
function genMenuItem($item, $level = 0, $pos = '', $ret = 0)
{
$data = null;
$tmp = $item;
if ($tmp->type == 'separator')
{
$data = '<a href="#" title=""><span class="separator">'.$tmp->name.'</span></a>';
if (!$ret) echo $data;
return $data;
}
// Print a link if it exists
$active = $this->genClass ($tmp, $level, $pos);
$id='id="menu' . $tmp->id . '"';
$iParams = $this->createParameterObject( $item->params );
//$iParams =& new JParameter($tmp->params);
$itembg = '';
if ($this->getParam('menu_images') && $iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
if ($this->getParam('menu_background')) {
$itembg = ' style="background-image:url(images/stories/'.$iParams->get('menu_image').');"';
$txt = '<span class="menu-title">' . $tmp->name . '</span>';
} else {
$txt = '<img src="images/stories/'.$iParams->get('menu_image').'" alt="'.$tmp->name.'" title="'.$tmp->name.'" /><span class="menu-title">' . $tmp->name . '</span>';
}
} else {
$txt = '<span class="menu-title">' . $tmp->name . '</span>';
}
//Add page title to item
if ($level == 0 && $this->getParam('menu_title')) {
if ($this->getPageTitle($iParams)) {
$txt .= '<span class="menu-desc">'. $this->getPageTitle($iParams).'</span>';
} else {
$txt .= '<span class="menu-desc">'. $tmp->name.'</span>';
}
}
$title = "title=\"$tmp->name\"";
if ($tmp->url != null)
{
switch ($tmp->browserNav)
{
default:
case 0:
// _top
$data = '<a href="'.$tmp->url.'" '.$active.' '.$id.' '.$title.$itembg.'>'.$txt.'</a>';
break;
case 1:
// _blank
$data = '<a href="'.$tmp->url.'" target="_blank" '.$active.' '.$id.' '.$title.$itembg.'>'.$txt.'</a>';
break;
case 2:
// window.open
$attribs = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,'.$this->getParam('window_open');
// hrm...this is a bit dickey
$link = str_replace('index.php', 'index2.php', $tmp->url);
$data = '<a href="'.$link.'" onclick="window.open(this.href,\'targetWindow\',\''.$attribs.'\');return false;" '.$active.' '.$id.' '.$title.$itembg.'>'.$txt.'</a>';
break;
}
} else {
$data = '<a '.$active.' '.$id.' '.$title.$itembg.'>'.$txt.'</a>';
}
if ($ret) return $data; else echo $data;
}
function getParam($paramName){
return $this->_params->get($paramName);
}
function setParam($paramName, $paramValue){
return $this->_params->set($paramName, $paramValue);
}
function beginMenu($startlevel=0, $endlevel = 10){
echo "<div>";
}
function endMenu($startlevel=0, $endlevel = 10){
echo "</div>";
}
function beginMenuItems($pid=0, $level=0){
echo "<ul>";
}
function endMenuItems($pid=0, $level=0){
echo "</ul>";
}
function beginMenuItem($mitem=null, $level = 0, $pos = ''){
echo "<li>";
}
function endMenuItem($mitem=null, $level = 0, $pos = ''){
echo "</li>";
}
function genClass ($mitem, $level, $pos) {
$active = in_array($mitem->id, $this->open);
$cls = ($level?"":"menu-item{$mitem->_idx}"). ($active?" active":"").($pos?" $pos-item":"");
return $cls?"class=\"$cls\"":"";
}
function hasSubMenu($level) {
$pid = $this->getParentId ($level);
if (!$pid) return false;
return $this->hasSubItems ($pid);
}
function hasSubItems($id){
if (@$this->children[$id]) return true;
return false;
}
function genMenu($startlevel=0, $endlevel = 10){
$this->setParam('startlevel', $startlevel);
$this->setParam('endlevel', $endlevel);
$this->beginMenu($startlevel, $endlevel);
if ($this->getParam('startlevel') == 0) {
//First level
$this->genMenuItems (0, 0);
}else{
//Sub level
$pid = $this->getParentId($this->getParam('startlevel'));
if ($pid)
$this->genMenuItems ($pid, $this->getParam('startlevel'));
}
$this->endMenu($startlevel, $endlevel);
}
/*
$pid: parent id
$level: menu level
$pos: position of parent
*/
function genMenuItems($pid, $level) {
if (@$this->children[$pid]) {
$this->beginMenuItems($pid, $level);
$i = 0;
foreach ($this->children[$pid] as $row) {
$pos = ($i == 0 ) ? 'first' : (($i == count($this->children[$pid])-1) ? 'last' :'');
$this->beginMenuItem($row, $level, $pos);
$this->genMenuItem( $row, $level, $pos);
// show menu with menu expanded - submenus visible
if ($level < $this->getParam('endlevel')) $this->genMenuItems( $row->id, $level+1 );
$i++;
if ($level == 0 && $pos == 'last' && in_array($row->id, $this->open)) {
global $jaMainmenuLastItemActive;
$jaMainmenuLastItemActive = true;
}
$this->endMenuItem($row, $level, $pos);
}
$this->endMenuItems($pid, $level);
}
}
function indentText($level, $text) {
echo "\n";
for ($i=0;$i<$level;++$i) echo " ";
echo $text;
}
function getParentId ($level) {
if (!$level || (count($this->open) < $level)) return 0;
return $this->open[count($this->open)-$level];
}
function getParentText ($level) {
$pid = $this->getParentId ($level);
if ($pid) {
return $this->items[$pid]->name;
}else return "";
}
function genMenuHead () {
}
}
}
?>
[/code]
Also on backend i get these:
Warning: call_user_func_array() expects parameter 2 to be array, null given in /users/venise/www/libraries/joomla/cache/cache.php on line 143
And
Warning: call_user_func_array() expects parameter 2 to be array, null given in /users/venise/www/libraries/joomla/session/session.php on line 272
Cache.php
[code]<?php
/**
- @version $Id: cache.php 10707 2008-08-21 09:52:47Z eddieajau $
- @package Joomla.Framework
- @subpackage Cache
- @copyright Copyright © 2005 - 2008 Open Source Matters. All rights reserved.
- @license GNU/GPL, see LICENSE.php
- Joomla! is free software. This version may have been modified pursuant to the
- GNU General Public License, and as distributed it includes or is derivative
- of works licensed under the GNU General Public License or other free or open
- source software licenses. See COPYRIGHT.php for copyright notices and
- details.
*/
// Check to ensure this file is within the rest of the framework
defined(‘JPATH_BASE’) or die();
//Register the session storage class with the loader
JLoader::register(‘JCacheStorage’, dirname(FILE).DS.‘storage.php’);
/**
-
Joomla! Cache base object
-
@abstract
-
@package Joomla.Framework
-
@subpackage Cache
-
@since 1.5
/
class JCache extends JObject
{
/*- Storage Handler
- @access private
-
@var object
*/
var $_handler;
/**
- Cache Options
- @access private
-
@var array
*/
var $_options;
/**
-
Constructor
-
@access protected
-
@param array $options options
*/
function __construct($options)
{
$this->_options =& $options;// Get the default group and caching
if(isset($options[‘language’])) {
$this->_options[‘language’] = $options[‘language’];
} else {
$options[‘language’] = ‘en-GB’;
}if(isset($options[‘cachebase’])) {
$this->_options[‘cachebase’] = $options[‘cachebase’];
} else {
$this->_options[‘cachebase’] = JPATH_ROOT.DS.‘cache’;
}if(isset($options[‘defaultgroup’])) {
$this->_options[‘defaultgroup’] = $options[‘defaultgroup’];
} else {
$this->_options[‘defaultgroup’] = ‘default’;
}if(isset($options[‘caching’])) {
$this->_options[‘caching’] = $options[‘caching’];
} else {
$this->_options[‘caching’] = true;
}if( isset($options[‘storage’])) {
$this->_options[‘storage’] = $options[‘storage’];
} else {
$this->_options[‘storage’] = ‘file’;
}//Fix to detect if template positions are enabled…
if(JRequest::getCMD(‘tpl’,0)) {
$this->_options[‘caching’] = false;
}
}
/**
-
Returns a reference to a cache adapter object, always creating it
-
@static
-
@param string $type The cache object type to instantiate
-
@return object A JCache object
-
@since 1.5
*/
function &getInstance($type = ‘output’, $options = array())
{
$type = strtolower(preg_replace(’/[^A-Z0-9_.-]/i’, ‘’, $type));$class = ‘JCache’.ucfirst($type);
if(!class_exists($class))
{
$path = dirname(FILE).DS.‘handler’.DS.$type.’.php’;if (file_exists($path)) { require_once($path); } else { JError::raiseError(500, 'Unable to load Cache Handler: '.$type); }
}
$instance = new $class($options);
return $instance;
}
/**
-
Get the storage handlers
-
@access public
-
@return array An array of available storage handlers
*/
function getStores()
{
jimport(‘joomla.filesystem.folder’);
$handlers = JFolder::files(dirname(FILE).DS.‘storage’, ‘.php$’);$names = array();
foreach($handlers as $handler)
{
$name = substr($handler, 0, strrpos($handler, ‘.’));
$class = ‘JCacheStorage’.$name;if(!class_exists($class)) { require_once(dirname(__FILE__).DS.'storage'.DS.$name.'.php'); } if(call_user_func_array( array( trim($class), 'test' ), null)) { $names[] = $name; }
}
return $names;
}
/**
- Set caching enabled state
- @access public
- @param boolean $enabled True to enable caching
- @return void
-
@since 1.5
*/
function setCaching($enabled)
{
$this->_options[‘caching’] = $enabled;
}
/**
- Set cache lifetime
- @access public
- @param int $lt Cache lifetime
- @return void
-
@since 1.5
*/
function setLifeTime($lt)
{
$this->_options[‘lifetime’] = $lt;
}
/**
- Set cache validation
- @access public
- @return void
-
@since 1.5
*/
function setCacheValidation()
{
// Deprecated
}
/**
-
Get cached data by id and group
-
@abstract
-
@access public
-
@param string $id The cache data id
-
@param string $group The cache data group
-
@return mixed Boolean false on failure or a cached data string
-
@since 1.5
*/
function get($id, $group=null)
{
// Get the default group
$group = ($group) ? $group : $this->_options[‘defaultgroup’];// Get the storage handler
$handler =& $this->_getStorage();
if (!JError::isError($handler) && $this->_options[‘caching’]) {
return $handler->get($id, $group, (isset($this->_options[‘checkTime’]))? $this->_options[‘checkTime’] : true);
}
return false;
}
/**
-
Store the cached data by id and group
-
@access public
-
@param string $id The cache data id
-
@param string $group The cache data group
-
@param mixed $data The data to store
-
@return boolean True if cache stored
-
@since 1.5
*/
function store($data, $id, $group=null)
{
// Get the default group
$group = ($group) ? $group : $this->_options[‘defaultgroup’];// Get the storage handler and store the cached data
$handler =& $this->_getStorage();
if (!JError::isError($handler) && $this->_options[‘caching’]) {
return $handler->store($id, $group, $data);
}
return false;
}
/**
-
Remove a cached data entry by id and group
-
@abstract
-
@access public
-
@param string $id The cache data id
-
@param string $group The cache data group
-
@return boolean True on success, false otherwise
-
@since 1.5
*/
function remove($id, $group=null)
{
// Get the default group
$group = ($group) ? $group : $this->_options[‘defaultgroup’];// Get the storage handler
$handler =& $this->_getStorage();
if (!JError::isError($handler)) {
return $handler->remove($id, $group);
}
return false;
}
/**
-
Clean cache for a group given a mode.
-
group mode : cleans all cache in the group
-
notgroup mode : cleans all cache not in the group
-
@access public
-
@param string $group The cache data group
-
@param string $mode The mode for cleaning cache [group|notgroup]
-
@return boolean True on success, false otherwise
-
@since 1.5
*/
function clean($group=null, $mode=‘group’)
{
// Get the default group
$group = ($group) ? $group : $this->_options[‘defaultgroup’];// Get the storage handler
$handler =& $this->_getStorage();
if (!JError::isError($handler)) {
return $handler->clean($group, $mode);
}
return false;
}
/**
- Garbage collect expired cache data
- @access public
- @return boolean True on success, false otherwise.
-
@since 1.5
*/
function gc()
{
// Get the storage handler
$handler =& $this->_getStorage();
if (!JError::isError($handler)) {
return $handler->gc();
}
return false;
}
/**
-
Get the cache storage handler
-
@access protected
-
@return object A JCacheStorage object
-
@since 1.5
*/
function &_getStorage()
{
if (is_a($this->_handler, ‘JCacheStorage’)) {
return $this->_handler;
}$this->_handler =& JCacheStorage::getInstance($this->_options[‘storage’], $this->_options);
return $this->_handler;
}
}
[/code]
Session.php
[code]<?php
/**
- @version $Id: session.php 10707 2008-08-21 09:52:47Z eddieajau $
- @package Joomla.Framework
- @subpackage Session
- @copyright Copyright © 2005 - 2008 Open Source Matters. All rights reserved.
- @license GNU/GPL, see LICENSE.php
- Joomla! is free software. This version may have been modified pursuant
- to the GNU General Public License, and as distributed it includes or
- is derivative of works licensed under the GNU General Public License or
- other free or open source software licenses.
- See COPYRIGHT.php for copyright notices and details.
*/
// Check to ensure this file is within the rest of the framework
defined(‘JPATH_BASE’) or die();
//Register the session storage class with the loader
JLoader::register(‘JSessionStorage’, dirname(FILE).DS.‘storage.php’);
/**
-
Class for managing HTTP sessions
-
Provides access to session-state values as well as session-level
-
settings and lifetime management methods.
-
Based on the standart PHP session handling mechanism it provides
-
for you more advanced features such as expire timeouts.
-
@package Joomla.Framework
-
@subpackage Session
-
@since 1.5
/
class JSession extends JObject
{
/*- internal state
- @access protected
- @var string $_state one of ‘active’|‘expired’|'destroyed|‘error’
-
@see getState()
*/
var $_state = ‘active’;
/**
- Maximum age of unused session
- @access protected
-
@var string $_expire minutes
*/
var $_expire = 15;
/**
- The session store object
- @access protected
-
@var object A JSessionStorage object
*/
var $_store = null;
/**
- security policy
- Default values:
-
- fix_browser
-
- fix_adress
- @access protected
-
@var array $_security list of checks that will be done.
*/
var $_security = array( ‘fix_browser’ );
/**
-
Constructor
-
@access protected
-
@param string $storage
-
@param array $options optional parameters
*/
function __construct( $store = ‘none’, $options = array() )
{
// Register faked “destructor” in PHP4, this needs to happen before creating the session store
if (version_compare(PHP_VERSION, ‘5’) == -1) {
register_shutdown_function((array(&$this, ‘__destruct’)));
}//Need to destroy any existing sessions started with session.auto_start
if (session_id()) {
session_unset();
session_destroy();
}//set default sessios save handler
ini_set(‘session.save_handler’, ‘files’);//disable transparent sid support
ini_set(‘session.use_trans_sid’, ‘0’);//create handler
$this->_store =& JSessionStorage::getInstance($store, $options);//set options
$this->_setOptions( $options );//load the session
$this->_start();//initialise the session
$this->_setCounter();
$this->_setTimers();$this->_state = ‘active’;
// perform security checks
$this->_validate();
}
/**
- Session object destructor
- @access private
-
@since 1.5
*/
function __destruct() {
$this->close();
}
/**
-
Returns a reference to the global Session object, only creating it
-
if it doesn’t already exist.
-
This method must be invoked as:
-
<pre> $session = &JSession::getInstance();</pre>
-
@access public
-
@return JSession The Session object.
-
@since 1.5
*/
function & getInstance($handler, $options)
{
static $instance;if (!is_object($instance)) {
$instance = new JSession($handler, $options);
}return $instance;
}
/**
- Get current state of session
- @access public
-
@return string The session state
*/
function getState() {
return $this->_state;
}
/**
- Get expiration time in minutes
- @access public
-
@return integer The session expiration time in minutes
*/
function getExpire() {
return $this->_expire;
}
/**
-
Get a session token, if a token isn’t set yet one will be generated.
-
Tokens are used to secure forms from spamming attacks. Once a token
-
has been generated the system will check the post request to see if
-
it is present, if not it will invalidate the session.
-
@param boolean $forceNew If true, force a new token to be created
-
@access public
-
@return string The session token
*/
function getToken($forceNew = false)
{
$token = $this->get( ‘session.token’ );//create a token
if( $token === null || $forceNew ) {
$token = $this->_createToken( 12 );
$this->set( ‘session.token’, $token );
}return $token;
}
/**
-
Method to determine if a token exists in the session. If not the
-
session will be set to expired
-
@param string Hashed token to be verified
-
@param boolean If true, expires the session
-
@since 1.5
-
@static
*/
function hasToken($tCheck, $forceExpire = true)
{
// check if a token exists in the session
$tStored = $this->get( ‘session.token’ );//check token
if(($tStored !== $tCheck))
{
if($forceExpire) {
$this->_state = ‘expired’;
}
return false;
}return true;
}
/**
- Get session name
- @access public
-
@return string The session name
*/
function getName()
{
if( $this->_state === ‘destroyed’ ) {
// @TODO : raise error
return null;
}
return session_name();
}
/**
- Get session id
- @access public
-
@return string The session name
*/
function getId()
{
if( $this->_state === ‘destroyed’ ) {
// @TODO : raise error
return null;
}
return session_id();
}
/**
-
Get the session handlers
-
@access public
-
@return array An array of available session handlers
*/
function getStores()
{
jimport(‘joomla.filesystem.folder’);
$handlers = JFolder::files(dirname(FILE).DS.‘storage’, ‘.php$’);$names = array();
foreach($handlers as $handler)
{
$name = substr($handler, 0, strrpos($handler, ‘.’));
$class = ‘JSessionStorage’.ucfirst($name);//Load the class only if needed if(!class_exists($class)) { require_once(dirname(__FILE__).DS.'storage'.DS.$name.'.php'); } if(call_user_func_array( array( trim($class), 'test' ), null)) { $names[] = $name; }
}
return $names;
}
/**
- Check whether this session is currently created
- @access public
-
@return boolean $result true on success
*/
function isNew()
{
$counter = $this->get( ‘session.counter’ );
if( $counter === 1 ) {
return true;
}
return false;
}
/**
-
Get data from the session store
-
@static
-
@access public
-
@param string $name Name of a variable
-
@param mixed $default Default value of a variable if not set
-
@param string $namespace Namespace to use, default to ‘default’
-
@return mixed Value of a variable
*/
function &get($name, $default = null, $namespace = ‘default’)
{
$namespace = ‘__’.$namespace; //add prefix to namespace to avoid collisionsif($this->_state !== ‘active’ && $this->_state !== ‘expired’) {
// @TODO :: generated error here
$error = null;
return $error;
}if (isset($_SESSION[$namespace][$name])) {
return $_SESSION[$namespace][$name];
}
return $default;
}
/**
-
Set data into the session store
-
@access public
-
@param string $name Name of a variable
-
@param mixed $value Value of a variable
-
@param string $namespace Namespace to use, default to ‘default’
-
@return mixed Old value of a variable
*/
function set($name, $value, $namespace = ‘default’)
{
$namespace = ‘__’.$namespace; //add prefix to namespace to avoid collisionsif($this->_state !== ‘active’) {
// @TODO :: generated error here
return null;
}$old = isset($_SESSION[$namespace][$name]) ? $_SESSION[$namespace][$name] : null;
if (null === $value) {
unset($_SESSION[$namespace][$name]);
} else {
$_SESSION[$namespace][$name] = $value;
}return $old;
}
/**
-
Check wheter data exists in the session store
-
@access public
-
@param string $name Name of variable
-
@param string $namespace Namespace to use, default to ‘default’
-
@return boolean $result true if the variable exists
*/
function has( $name, $namespace = ‘default’ )
{
$namespace = ‘__’.$namespace; //add prefix to namespace to avoid collisionsif( $this->_state !== ‘active’ ) {
// @TODO :: generated error here
return null;
}return isset( $_SESSION[$namespace][$name] );
}
/**
-
Unset data from the session store
-
@access public
-
@param string $name Name of variable
-
@param string $namespace Namespace to use, default to ‘default’
-
@return mixed $value the value from session or NULL if not set
*/
function clear( $name, $namespace = ‘default’ )
{
$namespace = ‘__’.$namespace; //add prefix to namespace to avoid collisionsif( $this->_state !== ‘active’ ) {
// @TODO :: generated error here
return null;
}$value = null;
if( isset( $_SESSION[$namespace][$name] ) ) {
$value = $_SESSION[$namespace][$name];
unset( $_SESSION[$namespace][$name] );
}return $value;
}
/**
-
Start a session
-
Creates a session (or resumes the current one based on the state of the session)
-
@access private
-
@return boolean $result true on success
*/
function _start()
{
// start session if not startet
if( $this->_state == ‘restart’ ) {
session_id( $this->_createId() );
}session_cache_limiter(‘none’);
session_start();// Send modified header for IE 6.0 Security Policy
header(‘P3P: CP=“NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM”’);return true;
}
/**
-
Frees all session variables and destroys all data registered to a session
-
This method resets the $_SESSION variable and destroys all of the data associated
-
with the current session in its storage (file or DB). It forces new session to be
-
started after this method is called. It does not unset the session cookie.
-
@static
-
@access public
-
@return void
-
@see session_unset()
-
@see session_destroy()
*/
function destroy()
{
// session was already destroyed
if( $this->_state === ‘destroyed’ ) {
return true;
}// In order to kill the session altogether, like to log the user out, the session id
// must also be unset. If a cookie is used to propagate the session id (default behavior),
// then the session cookie must be deleted.
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), ‘’, time()-42000, ‘/’);
}session_unset();
session_destroy();$this->_state = ‘destroyed’;
return true;
}
/**
-
restart an expired or locked session
-
@access public
-
@return boolean $result true on success
-
@see destroy
*/
function restart()
{
$this->destroy();
if( $this->_state !== ‘destroyed’ ) {
// @TODO :: generated error here
return false;
}// Re-register the session handler after a session has been destroyed, to avoid PHP bug
$this->_store->register();$this->_state = ‘restart’;
//regenerate session id
$id = $this->_createId( strlen( $this->getId() ) );
session_id($id);
$this->_start();
$this->_state = ‘active’;$this->_validate();
$this->_setCounter();return true;
}
/**
-
Create a new session and copy variables from the old one
-
@abstract
-
@access public
-
@return boolean $result true on success
*/
function fork()
{
if( $this->_state !== ‘active’ ) {
// @TODO :: generated error here
return false;
}// save values
$values = $_SESSION;// keep session config
$trans = ini_get( ‘session.use_trans_sid’ );
if( $trans ) {
ini_set( ‘session.use_trans_sid’, 0 );
}
$cookie = session_get_cookie_params();// create new session id
$id = $this->_createId( strlen( $this->getId() ) );// kill session
session_destroy();// re-register the session store after a session has been destroyed, to avoid PHP bug
$this->_store->register();// restore config
ini_set( ‘session.use_trans_sid’, $trans );
session_set_cookie_params( $cookie[‘lifetime’], $cookie[‘path’], $cookie[‘domain’], $cookie[‘secure’] );// restart session with new id
session_id( $id );
session_start();return true;
}
/**
- Writes session data and ends session
- Session data is usually stored after your script terminated without the need
- to call JSession::close(),but as session data is locked to prevent concurrent
- writes only one script may operate on a session at any time. When using
- framesets together with sessions you will experience the frames loading one
- by one due to this locking. You can reduce the time needed to load all the
- frames by ending the session as soon as all changes to session variables are
- done.
- @access public
-
@see session_write_close()
*/
function close() {
session_write_close();
}
/**
-
Create a session id
-
@static
-
@access private
-
@return string Session ID
*/
function _createId( )
{
$id = 0;
while (strlen($id) < 32) {
$id .= mt_rand(0, mt_getrandmax());
}$id = md5( uniqid($id, true));
return $id;
}
/**
-
Create a token-string
-
@access protected
-
@param int $length lenght of string
-
@return string $id generated token
*/
function _createToken( $length = 32 )
{
static $chars = ‘0123456789abcdef’;
$max = strlen( $chars ) - 1;
$token = ‘’;
$name = session_name();
for( $i = 0; $i < $length; ++$i ) {
$token .= $chars[ (rand( 0, $max )) ];
}return md5($token.$name);
}
/**
-
Set counter of session usage
-
@access protected
-
@return boolean $result true on success
*/
function _setCounter()
{
$counter = $this->get( ‘session.counter’, 0 );
++$counter;$this->set( ‘session.counter’, $counter );
return true;
}
/**
-
Set the session timers
-
@access protected
-
@return boolean $result true on success
*/
function _setTimers()
{
if( !$this->has( ‘session.timer.start’ ) )
{
$start = time();$this->set( 'session.timer.start' , $start ); $this->set( 'session.timer.last' , $start ); $this->set( 'session.timer.now' , $start );
}
$this->set( ‘session.timer.last’, $this->get( ‘session.timer.now’ ) );
$this->set( ‘session.timer.now’, time() );return true;
}
/**
-
set additional session options
-
@access protected
-
@param array $options list of parameter
-
@return boolean $result true on success
*/
function _setOptions( &$options )
{
// set name
if( isset( $options[‘name’] ) ) {
session_name( md5($options[‘name’]) );
}// set id
if( isset( $options[‘id’] ) ) {
session_id( $options[‘id’] );
}// set expire time
if( isset( $options[‘expire’] ) ) {
$this->_expire = $options[‘expire’];
}// get security options
if( isset( $options[‘security’] ) ) {
$this->_security = explode( ‘,’, $options[‘security’] );
}//sync the session maxlifetime
ini_set(‘session.gc_maxlifetime’, $this->_expire);return true;
}
/**
-
Do some checks for security reason
-
- timeout check (expire)
-
- ip-fixiation
-
- browser-fixiation
-
If one check failed, session data has to be cleaned.
-
@access protected
-
@param boolean $restart reactivate session
-
@return boolean $result true on success
-
@see http://shiflett.org/articles/the-truth-about-sessions
*/
function _validate( $restart = false )
{
// allow to restart a session
if( $restart )
{
$this->_state = ‘active’;$this->set( 'session.client.address' , null ); $this->set( 'session.client.forwarded' , null ); $this->set( 'session.client.browser' , null ); $this->set( 'session.token' , null );
}
// check if session has expired
if( $this->_expire )
{
$curTime = $this->get( ‘session.timer.now’ , 0 );
$maxTime = $this->get( ‘session.timer.last’, 0 ) + $this->_expire;// empty session variables if( $maxTime < $curTime ) { $this->_state = 'expired'; return false; }
}
// record proxy forwarded for in the session in case we need it later
if( isset( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) {
$this->set( ‘session.client.forwarded’, $_SERVER[‘HTTP_X_FORWARDED_FOR’]);
}// check for client adress
if( in_array( ‘fix_adress’, $this->_security ) && isset( $_SERVER[‘REMOTE_ADDR’] ) )
{
$ip = $this->get( ‘session.client.address’ );if( $ip === null ) { $this->set( 'session.client.address', $_SERVER['REMOTE_ADDR'] ); } else if( $_SERVER['REMOTE_ADDR'] !== $ip ) { $this->_state = 'error'; return false; }
}
// check for clients browser
if( in_array( ‘fix_browser’, $this->_security ) && isset( $_SERVER[‘HTTP_USER_AGENT’] ) )
{
$browser = $this->get( ‘session.client.browser’ );if( $browser === null ) { $this->set( 'session.client.browser', $_SERVER['HTTP_USER_AGENT']); } else if( $_SERVER['HTTP_USER_AGENT'] !== $browser ) {
// $this->_state = ‘error’;
// return false;
}
}
return true;
}
}
[/code]