/**
  * @todo expireSessionCookie()
  * @todo rememberMe(xx)
  * @todo forgetMe()
  * @see Zend_Registry::get('session');
  * @return Zend_Session_Namespace
  */
 protected function _initSession()
 {
     $options = $this->getOption('ca_mgr');
     $db = Zend_Db::factory($options['db']['session']['pdo'], $options['db']['session']);
     /**
      * automatically clean up expired session entries from session cache
      * use the modified and lifetime stamps to calculate expire time
      */
     if ($options['db']['session']['autocleanup'] == '1') {
         $stmt = $db->query('delete from front_session where (modified + lifetime * 2) < unix_timestamp()');
         # $stmt->execute();
     }
     //you can either set the Zend_Db_Table default adapter
     //or you can pass the db connection straight to the save handler $config
     // @see lifetimeColumn / lifetime / overrideLifetime, lifetime defaults to php.ini: session.gc_maxlifetime
     Zend_Db_Table_Abstract::setDefaultAdapter($db);
     $config = array('name' => 'front_session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
     //create your Zend_Session_SaveHandler_DbTable and
     //set the save handler for Zend_Session
     Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
     // Zend_Session::rememberMe(7200);
     //start your session!
     Zend_Session::start();
     $session = new Zend_Session_Namespace();
     if (!isset($session->started)) {
         $session->started = time();
     }
     if (!isset($session->authdata)) {
         $session->authdata = array('authed' => false);
     }
     Zend_Registry::set('session', $session);
     return $session;
 }
Exemple #2
0
 protected function _setupEnvironment()
 {
     error_reporting(E_ALL | E_STRICT);
     set_include_path($this->getPath('library') . PATH_SEPARATOR . $this->getPath('models') . PATH_SEPARATOR . $this->getPath('controllers') . PATH_SEPARATOR . get_include_path());
     require_once 'WebVista/Model/ORM.php';
     require_once 'User.php';
     require_once 'Person.php';
     require_once 'Zend/Session.php';
     require_once 'WebVista/Session/SaveHandler.php';
     Zend_Session::setSaveHandler(new WebVista_Session_SaveHandler());
     Zend_Session::start();
     require_once 'Zend/Loader.php';
     Zend_Loader::registerAutoLoad();
     $sessionTimeout = ini_get('session.gc_maxlifetime') - 5 * 60;
     Zend_Registry::set('sessionTimeout', $sessionTimeout);
     $this->_config = new Zend_Config_Ini($this->getPath('application') . "/config/app.ini", APPLICATION_ENVIRONMENT);
     Zend_Registry::set('config', $this->_config);
     Zend_Registry::set('baseUrl', substr($_SERVER['PHP_SELF'], 0, strpos(strtolower($_SERVER['PHP_SELF']), 'index.php')));
     Zend_Registry::set('basePath', $this->getPath('base') . DIRECTORY_SEPARATOR);
     try {
         date_default_timezone_set(Zend_Registry::get('config')->date->timezone);
     } catch (Zend_Exception $e) {
         die($e->getMessage());
     }
     AuditLog::setDbConfig($this->_config->database->toArray());
     // this MUST be required as this is used as DB connection
     // register shutdown function
     register_shutdown_function(array('AuditLog', 'closeConnection'));
     ob_start();
     // this MUST be required after register shutdown
     return $this;
 }
Exemple #3
0
 public function init()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $config = $registry->get("config");
     $sessionConfig = $config['resources']['session'];
     $cookieLifetime = $sessionConfig['cookie_lifetime'];
     /* @todo fix issue of system with incoherent behavior when the session
        system has a issue, such as when the savehandler doesn't work as
        expected when it's off-line which results in differents
        catched / uncatched exception when the resource (page) loads
        */
     $saveHandler = new Ml_Session_SaveHandler_PlusCache($registry->get("memCache"), $config['session']['prefix'], $config['lastActivity']['prefix']);
     Zend_Session::setSaveHandler($saveHandler);
     Zend_Session::getSaveHandler()->setLifetime($cookieLifetime, true);
     Zend_Session::start();
     $defaultNamespace = new Zend_Session_Namespace();
     if (!isset($defaultNamespace->initialized)) {
         Zend_Session::regenerateId();
         $defaultNamespace->initialized = true;
     }
     if ($auth->hasIdentity()) {
         $people = Ml_Model_People::getInstance();
         $signedUserInfo = $people->getById($auth->getIdentity());
         $registry->set('signedUserInfo', $signedUserInfo);
     }
     $globalHash = Ml_Model_MagicCookies::getInstance()->getLast(true);
     $registry->set("globalHash", $globalHash);
 }
Exemple #4
0
 /**
  * Setup db
  *
  */
 public function setup(Zend_Config $config)
 {
     $sessionConfig = $config->get('config');
     $configArray = $sessionConfig->toArray();
     // save_path handler
     $configArray = $this->_prependSavePath($configArray);
     // name handler
     $configArray = $this->_parseName($configArray);
     // Setup config
     Zend_Session::setOptions($configArray);
     // Setup save handling?
     $saveHandlerConfig = $config->get('save_handler');
     if ($className = $saveHandlerConfig->get('class_name')) {
         if ($args = $saveHandlerConfig->get('constructor_args')) {
             if ($args instanceof Zend_Config) {
                 $args = $args->toArray();
             } else {
                 $args = (array) $args;
             }
         } else {
             $args = array();
         }
         require_once 'Zend/Loader.php';
         Zend_Loader::loadClass($className);
         $saveHandler = new ReflectionClass($className);
         $saveHandler = $saveHandler->newInstanceArgs($args);
         Zend_Session::setSaveHandler($saveHandler);
     }
     // Autostart session?
     if ($config->get('auto_start')) {
         // Start session
         Zend_Session::start();
     }
 }
Exemple #5
0
 protected function _initSession()
 {
     if ($this->hasPluginResource('session') && !Zend_Session::getSaveHandler()) {
         Zend_Session::setSaveHandler($this->getPluginResource('session')->getSaveHandler());
     }
     Zend_Session::start();
 }
Exemple #6
0
 protected function _initSession()
 {
     $configSession = new Zend_Config_Ini(APPLICATION_PATH . '/configs/session.ini', APPLICATION_ENV);
     if (!$this->_request->isInstalling()) {
         $config = array('name' => 'session', 'primary' => 'session_id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'lifetime' => $configSession->gc_maxlifetime);
         Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
     }
     if (!$this->_request->isInstalling() or is_writable(Core_Model_Directory::getSessionDirectory(true))) {
         $types = array();
         $options = $configSession->toArray();
         if (isset($options['types'])) {
             $types = $options['types'];
             unset($options['types']);
         }
         Zend_Session::start($options);
         $session_type = $this->_request->isApplication() ? 'mobile' : 'front';
         $session = new Core_Model_Session($session_type);
         foreach ($types as $type => $class) {
             $session->addType($type, $class);
         }
         $language_session = new Core_Model_Session('language');
         if (!$language_session->current_language) {
             $language_session->current_language = null;
         }
         Core_Model_Language::setSession($language_session);
         Core_View_Default::setSession($session);
         Core_Controller_Default::setSession($session);
     }
 }
Exemple #7
0
 /**
  * 系统初始化
  */
 private static function init()
 {
     set_exception_handler(array('AWS_APP', 'exception_handle'));
     self::$config = load_class('core_config');
     self::$db = load_class('core_db');
     self::$plugins = load_class('core_plugins');
     self::$settings = self::model('setting')->get_settings();
     if ((!defined('G_SESSION_SAVE') or G_SESSION_SAVE == 'db') and get_setting('db_version') > 20121123) {
         Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(array('name' => get_table('sessions'), 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime')));
         self::$session_type = 'db';
     }
     Zend_Session::setOptions(array('name' => G_COOKIE_PREFIX . '_Session', 'cookie_domain' => G_COOKIE_DOMAIN));
     if (G_SESSION_SAVE == 'file' and G_SESSION_SAVE_PATH) {
         Zend_Session::setOptions(array('save_path' => G_SESSION_SAVE_PATH));
     }
     Zend_Session::start();
     self::$session = new Zend_Session_Namespace(G_COOKIE_PREFIX . '_Anwsion');
     if ($default_timezone = get_setting('default_timezone')) {
         date_default_timezone_set($default_timezone);
     }
     if ($img_url = get_setting('img_url')) {
         define('G_STATIC_URL', $img_url);
     } else {
         define('G_STATIC_URL', base_url() . '/static');
     }
     if (self::config()->get('system')->debug) {
         if ($cornd_timer = self::cache()->getGroup('crond')) {
             foreach ($cornd_timer as $cornd_tag) {
                 if ($cornd_runtime = self::cache()->get($cornd_tag)) {
                     AWS_APP::debug_log('crond', 0, 'Tag: ' . str_replace('crond_timer_', '', $cornd_tag) . ', Last run time: ' . date('Y-m-d H:i:s', $cornd_runtime));
                 }
             }
         }
     }
 }
Exemple #8
0
 public function init()
 {
     $cookie_timeout = 60 * 60 * 24;
     $garbage_timeout = $cookie_timeout + 600;
     $aServerName = explode('.', $_SERVER['SERVER_NAME']);
     $count = count($aServerName);
     $domainName = '.' . $aServerName[$count - 2] . '.' . $aServerName[$count - 1];
     //session_set_cookie_params($cookie_timeout, '/', $domainName);
     session_set_cookie_params(0, '/', $domainName);
     ini_set('session.gc_maxlifetime', $garbage_timeout);
     ini_set('session.cookie_lifetime', $garbage_timeout);
     //		$session = new Zend_Session_Namespace();
     $options = array_change_key_case($this->getOptions(), CASE_LOWER);
     if (isset($options['adapter'])) {
         $adapter = $options['adapter'];
     }
     switch (strtolower($adapter)) {
         case 'remote':
         case 'proxydb':
             $sessionHandler = new Pandamp_Session_SaveHandler_Remote();
             Zend_Session::setSaveHandler($sessionHandler);
             //$this->_saveHandler = $sessionHandler;
             //return $sessionHandler;
             break;
         default:
         case 'directdb':
             $sessionHandler = new Pandamp_Session_SaveHandler_DirectDb($options['db']['adapter'], $options['db']['params']);
             Zend_Session::setSaveHandler($sessionHandler);
             $this->_saveHandler = $sessionHandler;
             return $sessionHandler;
             break;
     }
 }
 /**
  * initalize session
  */
 protected function _initSession()
 {
     $resource = $this->getPluginResource('db');
     $db = $resource->getDbAdapter();
     Zend_Db_Table_Abstract::setDefaultAdapter($db);
     $config = array('name' => 'sessions', 'primary' => 'sessionId', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'lifetime' => 60 * 60 * 24 * 14);
     Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
 }
Exemple #10
0
 public function setSaveHandler()
 {
     $registry = Zend_Registry::getInstance();
     $application = $registry->get(Pandamp_Keys::REGISTRY_APP_OBJECT);
     $application->getBootstrap()->bootstrap('session');
     $saveHandler = $application->getBootstrap()->getResource('session');
     Zend_Session::setSaveHandler($saveHandler);
 }
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return void
  */
 public function init()
 {
     $options = array_change_key_case($this->getOptions(), CASE_LOWER);
     if (isset($options['savehandler'])) {
         unset($options['savehandler']);
     }
     if (count($options) > 0) {
         Zend_Session::setOptions($options);
     }
     if ($this->_saveHandler !== null) {
         Zend_Session::setSaveHandler($this->_saveHandler);
     }
 }
Exemple #12
0
 function start()
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get('config');
     $url = $config->session->config->remote->sessionidgenerator->url;
     require_once 'Zend/Session.php';
     $saveHandler = $config->session->savehandler;
     $flagDoSyncSession = $this->_flagDoSyncSession;
     switch (strtolower($saveHandler)) {
         case 'remote':
             require_once 'Kutu/Session/SaveHandler/Remote.php';
             $sessionHandler = new Kutu_Session_SaveHandler_Remote();
             Zend_Session::setSaveHandler($sessionHandler);
             break;
         default:
             $flagDoSyncSession = false;
             break;
     }
     if ($this->_flagDoSyncSession) {
         $flagSessionIdSent = false;
         if (isset($_POST['PHPSESSID']) && !empty($_POST['PHPSESSID'])) {
             $sessid = $_POST['PHPSESSID'];
             Zend_Session::setId($sessid);
             $flagSessionIdSent = true;
         }
         if (isset($_GET['PHPSESSID']) && !empty($_GET['PHPSESSID'])) {
             $sessid = $_GET['PHPSESSID'];
             Zend_Session::setId($sessid);
             $flagSessionIdSent = true;
         }
         if (isset($_COOKIE['PHPSESSID']) && !empty($_COOKIE['PHPSESSID'])) {
             $flagSessionIdSent = true;
         }
         if (!$flagSessionIdSent) {
             //redirect to session local sync startpoint
             $sReturn = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
             $sReturn = base64_encode($sReturn);
             $url = $config->session->config->local->sync->url;
             $url = KUTU_ROOT_URL . $url;
             header("location: {$url}?returnTo=" . $sReturn);
             exit;
         } else {
             Zend_Session::start();
         }
     } else {
         Zend_Session::start();
     }
 }
 private function __construct()
 {
     /* Explicitly start the session */
     $config = array('name' => 'session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'db' => Zend_Registry::get("dbAdapter"));
     Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
     //start your session
     Zend_Session::start();
     /* Create our Session namespace - using 'Default' namespace */
     $this->namespace = new Zend_Session_Namespace();
     /** Check that our namespace has been initialized - if not, regenerate the session id
      * Makes Session fixation more difficult to achieve
      */
     if (!isset($this->namespace->initialized)) {
         Zend_Session::regenerateId();
         $this->namespace->initialized = true;
     }
 }
Exemple #14
0
 public function init()
 {
     // timeout value for the cookie
     $cookie_timeout = 60 * 60 * 24;
     // in seconds
     //$cookie_timeout = 1440;
     // timeout value for the garbage collector
     // we add 300 seconds, just in case the user's computer clock
     // was synchronized meanwhile; 600 secs (10 minutes) should be
     // enough - just to ensure there is session data until the
     // cookie expires
     $garbage_timeout = $cookie_timeout + 600;
     // in seconds
     // set the PHP session id (PHPSESSID) cookie to a custom value
     session_set_cookie_params($cookie_timeout);
     // set the garbage collector - who will clean the session files -
     // to our custom timeout
     ini_set('session.gc_maxlifetime', $garbage_timeout);
     // ini_set('session.gc_probability', '1');
     // ini_set('session.gc_divisor', '1');
     //die('identity:'.ini_get('session.gc_maxlifetime'));
     $options = array_change_key_case($this->getOptions(), CASE_LOWER);
     if (isset($options['adapter'])) {
         $adapter = $options['adapter'];
         //unset($options['savehandler']);
     }
     switch (strtolower($adapter)) {
         case 'remote':
         case 'proxydb':
             $sessionHandler = new Kutu_Session_SaveHandler_Remote();
             Zend_Session::setSaveHandler($sessionHandler);
             $this->_saveHandler = $sessionHandler;
             return $sessionHandler;
             break;
         default:
         case 'directdb':
             require_once 'Kutu/Session/SaveHandler/DirectDb.php';
             $sessionHandler = new Kutu_Session_SaveHandler_DirectDb($options['db']['adapter'], $options['db']['params']);
             Zend_Session::setSaveHandler($sessionHandler);
             $this->_saveHandler = $sessionHandler;
             return $sessionHandler;
             break;
     }
 }
Exemple #15
0
 public function setSaveHandler()
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get('config');
     $saveHandler = $config->session->savehandler;
     switch (strtolower($saveHandler)) {
         case 'remote':
         case 'proxydb':
             $sessionHandler = new Kutu_Session_SaveHandler_Remote();
             Zend_Session::setSaveHandler($sessionHandler);
             break;
         default:
         case 'directdb':
             require_once 'Kutu/Session/SaveHandler/DirectDb.php';
             $sessionHandler = new Kutu_Session_SaveHandler_DirectDb();
             Zend_Session::setSaveHandler($sessionHandler);
             break;
     }
 }
Exemple #16
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $config = Zend_Registry::get('config');
     //this is the only place where i want to have another cache instance - for zend_db metadata we should use file cache
     Zend_Db_Table_Abstract::setDefaultMetadataCache(Zend_Registry::get('cache_files'));
     $db = Zend_Db::factory($config->setup->database->adapter, $config->setup->database->config->toArray());
     #TODO did they implement that in 1.7 or still we have to wait :/
     switch ($config->setup->database) {
         case 'PDO_PGSQL':
             $db->query("SET NAMES 'UNICODE'");
             break;
         case 'PDO_MYSQL':
             $db->query("SET NAMES 'utf8'");
             break;
         default:
             break;
     }
     #start up the profiler if needed
     if ($config->setup->database->profiler == true) {
         $db->getProfiler()->setEnabled($config->setup->database->profiler);
     }
     Zend_Db_Table::setDefaultAdapter($db);
     #TODO database driven sessions - maybe we want to change that in future ? for better scaling ?
     Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(array('name' => 'session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime')));
     //set up the view
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->init();
     $view = $viewRenderer->view;
     $view->addHelperPath('Reactor/View/Helper', 'Reactor_View_Helper');
     Zend_Dojo::enableView($view);
     $view->doctype('XHTML1_STRICT');
     $view->setEncoding('UTF-8');
     $view->request = $this->getRequest();
     $view->baseUrl = $this->getRequest()->getBaseUrl();
     $this->locale = new Zend_Locale($config->setup->defaultLocale);
     Zend_Registry::set('Zend_Locale', $this->locale);
     Zend_Translate::setCache(Zend_Registry::get('cache'));
     #TODO currently hardcoded
     Zend_Registry::set('Zend_Translate', new Zend_Translate('gettext', '../data/locales/en_GB/LC_MESSAGES/default.mo', 'en'));
     Zend_Registry::set('Users', new Users());
 }
Exemple #17
0
 /**
  * @brief   _initSession method - initialises session management
  * 
  * Initialises session management.
  */
 protected function _initSession()
 {
     // init session only when not called from the cli
     if (php_sapi_name() !== 'cli') {
         $dbAdapter = null;
         $dbResource = $this->getPluginResource('db');
         if ($dbResource !== null) {
             // we are using the regular db resource
             $this->bootstrap('db');
             $dbAdapter = $dbResource->getDbAdapter();
         } else {
             // we are using multidb
             $this->bootstrap('multidb');
             $multidbResource = $this->getPluginResource('multidb');
             $dbAdapter = $multidbResource->getDefaultDb();
         }
         // sanity checks
         $error = false;
         if ($dbAdapter === null) {
             $error = true;
         }
         try {
             if (count($dbAdapter->listTables()) == 0) {
                 $error = true;
             }
         } catch (Exception $e) {
             $error = true;
         }
         if ($error === true) {
             header('HTTP/1.1 503 Service Temporarily Unavailable', true, 503);
             echo '<h1>The application is not correctly set up.</h1>';
             die;
         }
         $config = array('name' => 'Auth_Sessions', 'primary' => 'session', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'db' => $dbAdapter);
         Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
         Zend_Session::start();
     }
 }
Exemple #18
0
 /**
  * Sets up view
  * Alters response content type headers
  * Starts session
  *
  * @param Zend_Controller_Request_Abstract $request
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $this->setupView();
     parent::dispatchLoopStartup($request);
     // Since we're not using the cli sapi, instanciate the http protocol items
     if (!Zend_Session::isStarted() && !Zend_Session::sessionExists()) {
         if ($config = Zoo::getConfig('session', 'plugin')) {
             $options = $config->toArray();
             if (isset($options['save_path'])) {
                 $options['save_path'] = ZfApplication::$_data_path . $options['save_path'];
                 if (!file_exists($options['save_path'])) {
                     mkdir($options['save_path']);
                 }
             }
             Zend_Session::setOptions($options);
             if ($config->save_handler) {
                 $savehandlerClass = $config->save_handler;
                 Zend_Session::setSaveHandler(new $savehandlerClass());
                 // Not ready yet
             }
         }
         Zend_Session::start();
     }
 }
 /**
  * Bootstraps session
  *
  * @param Uni_Application_Bootstrap $bootS
  * @return void
  */
 public static function initSession($bootS)
 {
     if (Fox::getMode() != Uni_Controller_Action::MODE_INSTALL) {
         session_set_cookie_params(0);
         if (!Fox::isDatabaseSession()) {
             Zend_Session::start(array('save_path' => APPLICATION_PATH . '/../var/sessions'));
         } else {
             $config = array('name' => Fox::getTableName('core_session'), 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
             Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
             Zend_Session::start();
         }
     }
 }
Exemple #20
0
}
/*
 * Check CACHE_DIR is writable
 */
if (!is_writable(CACHE_DIR)) {
    echo '<pre>';
    throw new Zend_Exception('Directory "' . CACHE_DIR . '" is not exists or not writable.');
}
/*
 * Start session
 */
Zend_Session::setOptions(array('use_only_cookies' => 1));
//create your Zend_Session_SaveHandler_DbTable and
//set the save handler for Zend_Session
$config_session = array('name' => 'webacula_php_session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'lifetimeColumn' => 'lifetime', 'dataColumn' => 'data_session');
Zend_Session::setSaveHandler(new MyClass_Session_SaveHandler_DbTable($config_session));
Zend_Session::start();
if (APPLICATION_ENV == 'production') {
    Zend_Session::regenerateId();
}
/*
 * для подсчета кол-ва неудачных логинов для вывода капчи
 */
$defNamespace = new Zend_Session_Namespace('Default');
if (!isset($defNamespace->numLoginFails)) {
    $defNamespace->numLoginFails = 0;
}
// initial value
/*
 * Zend_Cache
 */
Exemple #21
0
 public function testSessionSaving()
 {
     $this->_dropTable();
     $config = $this->_saveHandlerTableConfig;
     unset($config[Zend_Session_SaveHandler_DbTable::PRIMARY_ASSIGNMENT]);
     $config['primary'] = array($config['primary'][0]);
     $this->_setupDb($config['primary']);
     $this->_usedSaveHandlers[] = $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
     Zend_Session::setSaveHandler($saveHandler);
     Zend_Session::start();
     /**
      * @see Zend_Session_Namespace
      */
     // require_once 'Zend/Session/Namespace.php';
     $session = new Zend_Session_Namespace('SaveHandler');
     $session->testArray = $this->_saveHandlerTableConfig;
     $tmp = array('SaveHandler' => serialize(array('testArray' => $this->_saveHandlerTableConfig)));
     $testAgainst = '';
     foreach ($tmp as $key => $val) {
         $testAgainst .= $key . "|" . $val;
     }
     session_write_close();
     foreach ($this->_db->query('SELECT * FROM Sessions')->fetchAll() as $row) {
         $this->assertSame($row[$config[Zend_Session_SaveHandler_DbTable::DATA_COLUMN]], $testAgainst, 'Data was not saved properly');
     }
 }
Exemple #22
0
 protected function _initSession()
 {
     if (Zend_Session::isStarted()) {
         return $this;
     }
     $configSession = new Zend_Config_Ini(APPLICATION_PATH . '/configs/session.ini', APPLICATION_ENV);
     if (!$this->getRequest()->isInstalling()) {
         $config = array('name' => 'session', 'primary' => 'session_id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime', 'lifetime' => $configSession->gc_maxlifetime);
         Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
     }
     if (!$this->getRequest()->isInstalling() or is_writable(Core_Model_Directory::getSessionDirectory(true))) {
         $options = $configSession->toArray();
         Zend_Session::start($options);
         $session_type = 'front';
         if ($this->getRequest()->isApplication()) {
             $session_type = 'mobile';
         } else {
             if ($this->_isInstanceOfBackoffice()) {
                 $session_type = 'backoffice';
             }
         }
         defined('SESSION_TYPE') || define('SESSION_TYPE', $session_type);
         $session = new Core_Model_Session($session_type);
         Core_Model_Language::setSession($session);
         Core_View_Default::setSession($session, $session_type);
         Core_Model_Default::setSession($session, $session_type);
         self::setSession($session, $session_type);
     }
 }
Exemple #23
0
 public function initSession()
 {
     @ini_set('session.use_trans_sid', false);
     @ini_set('session.cookie_httponly', true);
     // lifetime must be bigger than admin and user auth timeout
     $lifetime = (int) ini_get('session.gc_maxlifetime');
     if ($lifetime < ($max = max($this->di->config->get('login_session_lifetime', 120) * 60, 7200))) {
         @ini_set('session.gc_maxlifetime', $max);
     }
     $this->setSessionCookieDomain();
     if ('db' == $this->getSessionStorageType()) {
         Zend_Session::setSaveHandler(new Am_Session_SaveHandler($this->di->db));
     }
     if (defined('AM_SESSION_NAME') && AM_SESSION_NAME) {
         Zend_Session::setOptions(array('name' => AM_SESSION_NAME));
     }
     try {
         Zend_Session::start();
     } catch (Zend_Session_Exception $e) {
         // fix for Error #1009 - Internal error when disable shopping cart module
         if (strpos($e->getMessage(), "Failed opening 'Am/ShoppingCart.php'") !== false) {
             Zend_Session::destroy();
             header("Location: " . $_SERVER['REQUEST_URI']);
             exit;
         }
         // process other session issues
         if (strpos($e->getMessage(), 'This session is not valid according to') === 0) {
             $_SESSION = array();
             Zend_Session::regenerateId();
             Zend_Session::writeClose();
         }
         if (defined('AM_TEST') && AM_TEST) {
             // just ignore error
         } else {
             throw $e;
         }
     }
     // Workaround to fix bug: https://bugs.php.net/bug.php?id=68063
     // Sometimes php starts session with empty session_id()
     if (!defined('AM_TEST') && !Zend_Session::getId()) {
         Zend_Session::destroy();
         header("Location: " . $_SERVER['REQUEST_URI']);
         exit;
     }
     //disabled as it brokes flash uploads !
     //Zend_Session::registerValidator(new Zend_Session_Validator_HttpUserAgent);
     $this->di->session = new Zend_Session_Namespace('amember');
 }
Exemple #24
0
class SaveHandler implements Zend_Session_SaveHandler_Interface
{
    function open($save_path, $session_name)
    {
        return true;
    }
    function close()
    {
        return true;
    }
    function read($id)
    {
        return '';
    }
    function write($id, $sess_data)
    {
        throw new Exception("test exception within session save handler");
        return true;
    }
    function destroy($id)
    {
        return true;
    }
    function gc($maxlifetime)
    {
        return true;
    }
}
$savehandler = new SaveHandler();
Zend_Session::setSaveHandler($savehandler);
Zend_Session::start();
Exemple #25
0
<?php

include_once '../bootstrap.php';
Zend_Layout::startMvc();
$cache = Yadda_Cache::getInstance();
if ($cache !== null) {
    Zend_Session::setSaveHandler(new Yadda_Session_SaveHandler($cache));
}
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(array('www' => APPLICATION_BASE . '/modules/www/controllers'))->setDefaultModule('www')->setRouter(new Www_Controller_Router())->dispatch();
Exemple #26
0
 public function startSession(Zend_Db_Adapter_Abstract $database, array $options = array())
 {
     try {
         if (!$this->_sessionStarted) {
             $this->_sessionStarted = true;
             require_once 'Zend/Session.php';
             require_once 'Sitengine/Session/SaveHandler.php';
             Zend_Session::setSaveHandler(new Sitengine_Session_SaveHandler($database));
             Zend_Session::setOptions(array_merge(array('name' => self::PARAM_SESSIONID), $options));
             Zend_Session::start();
         }
     } catch (Exception $exception) {
         require_once 'Sitengine/Env/Exception.php';
         throw new Sitengine_Env_Exception('start session error', $exception);
     }
 }
<?php

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
//get your database connection ready
$db = Zend_Db::factory('Pdo_Mssql', array('host' => 'localhost', 'username' => 'user', 'password' => 'password', 'dbname' => 'Database'));
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$config = array('name' => 'session', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
Zend_Session::start();
$defaultNamespace = new Zend_Session_Namespace('Default');
// Works
$defaultNamespace->requests++;
// Doesnt Work
class Foo
{
    protected $_bar;
}
$defaultNamespace->serializedData = serialize(array("foo" => new Foo()));
var_dump($_SESSION);
echo "Session should save after this";
Exemple #28
0
 protected function _initSession()
 {
     // Get session configuration
     $file = APPLICATION_PATH . '/application/settings/session.php';
     $config = array();
     if (file_exists($file)) {
         $config = (include $file);
     }
     // Get default session configuration
     if (empty($config)) {
         $config = array('options' => array('save_path' => 'session', 'use_only_cookies' => true, 'remember_me_seconds' => 864000, 'gc_maxlifetime' => 86400, 'cookie_httponly' => false), 'saveHandler' => array('class' => 'Core_Model_DbTable_Session', 'params' => array('lifetime' => 86400)));
     }
     // Remove httponly unless forced in config
     if (!isset($config['options']['cookie_httponly'])) {
         $config['options']['cookie_httponly'] = false;
     }
     // Set session options
     Zend_Session::setOptions($config['options']);
     $saveHandler = $config['saveHandler']['class'];
     Zend_Session::setSaveHandler(new $saveHandler($config['saveHandler']['params']));
     // Session hack for fancy upload
     //if( !isset($_COOKIE[session_name()]) )
     //{
     $sessionName = Zend_Session::getOptions('name');
     if (isset($_POST[$sessionName])) {
         Zend_Session::setId($_POST[$sessionName]);
     } else {
         if (isset($_POST['PHPSESSID'])) {
             Zend_Session::setId($_POST['PHPSESSID']);
         }
     }
     //}
     //Zend_Session::start();
 }
 /**
  * Init session
  */
 protected function _initSession()
 {
     if (!$this->_appConfig->session_lifetime) {
         return;
     }
     // session storage db table
     $config = array('name' => 'sessions', 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime');
     $saveHandler = new Zend_Session_SaveHandler_DbTable($config);
     // run garbage collector in 1%
     if (rand(1, 100) == 1) {
         $saveHandler->gc(1);
     }
     // make the session persist for x seconds
     $saveHandler->setLifetime($this->_appConfig->session_lifetime, $this->_appConfig->session_lifetime);
     Zend_Session::setSaveHandler($saveHandler);
     Zend_Session::start(array('cookie_lifetime' => $this->_appConfig->session_lifetime));
 }
Exemple #30
0
 /**
  * @return \Zend_Session_Namespace
  * @throws Exception
  * @throws \Exception
  * @throws \Zend_Exception
  */
 protected static function initSession()
 {
     if (static::isInCliCall()) {
         throw new Exception('Application', 'Cli tasks is not allowed to create session data');
     }
     $cfg = \Zend_Registry::get('config');
     if (!$cfg instanceof \Zend_Config) {
         throw new \Exception('Application', 'Configuration not found');
     }
     $sessionConfig = $cfg->session->toArray();
     \Zend_Session::setOptions(array('name' => SaveHandler::getSessionPrefix(), 'gc_maxlifetime' => $sessionConfig['gc_maxlifetime'], 'remember_me_seconds' => $sessionConfig['remember_me_seconds']));
     if (isset($sessionConfig['adapter'])) {
         $saveHandler = new SaveHandler(Factory::create($sessionConfig['adapter']), SaveHandler::SESSION_TIMEOUT);
         \Zend_Session::setSaveHandler($saveHandler);
     }
     $session = new \Zend_Session_Namespace(SaveHandler::SESSION_NAME);
     \Zend_Registry::set(Constants::CZE_SESSION, $session);
     return $session;
 }