Example #1
0
<?php

//ini_set('session.save_handler', 'memcache');
//ini_set('session.save_path',  'tcp://'.cache_memcache_server .':'. cache_memcache_port.'?persistent=1&amp;weight=1&amp;timeout=1&amp;retry_interval=15');
session_set_save_handler(array('Core\\Session', 'open'), array('Core\\Session', 'close'), array('Core\\Session', 'read'), array('Core\\Session', 'write'), array('Core\\Session', 'destroy'), array('Core\\Session', 'gc'));
//get the token
$token = isset($_REQUEST['token']) ? $_REQUEST['token'] : null;
if (!is_null($token)) {
    $sessionId = Auth_Session::getSessionIdByToken($token);
    if ($sessionId) {
        session_id($sessionId);
    }
}
session_start();
/*
 * keeps the session id changed every 10 minutes
 * */
if (!isset($_SESSION['session.created'])) {
    $_SESSION['session.created'] = time();
} else {
    if (time() - $_SESSION['session.created'] > 600) {
        $ds = Core\Ds::connect(ds_token);
        $cachedId = session_id();
        session_regenerate_id(true);
        try {
            $ds->update(array('snid' => $cachedId), array('$set' => array('snid' => session_id())));
        } catch (Exception $e) {
            Log::write('Exception: ' . $e->getCode() . ' ' . $e->getMessage());
        }
        $_SESSION['session.created'] = time();
    }
Example #2
0
 public function __construct(Core\Request $request)
 {
     $this->__pmg_request =& $request;
     //date_default_timezone_set('America/Denver');
     date_default_timezone_set('UTC');
     $this->__sessionOwner = Auth_Session::getSessionOwner();
     if (is_callable(array($this, 'pre_init'))) {
         $this->pre_init();
     }
     try {
         $this->init();
     } catch (Exception $e) {
         if ($e->getCode() == 404) {
             if ($this->__pmg_request->is_xmlHttpRequest) {
                 header('Content-type: application/json');
                 echo json_encode(array('success' => false, 'code' => $e->getCode(), 'message' => 'Page not found'));
                 exit;
             } else {
                 ob_start();
                 header('HTTP/1.0 404 Not Found');
                 $__page = (object) array('title' => Core\Utils::get_page_title('Page Not Found'), 'sections' => array(app_core_path . '/default/tpl/404.php'), 'assets' => array());
                 require_once '../templates/base.min.php';
                 ob_end_flush();
                 exit;
             }
         } else {
             throw $e;
         }
     }
     if (is_callable(array($this, 'post_init'))) {
         $this->post_init();
     }
 }