コード例 #1
0
 /**
  * Initialise session
  */
 function initSession()
 {
     switch (ONXSHOP_SESSION_TYPE) {
         case 'file':
             ini_set('session.save_path', ONXSHOP_PROJECT_DIR . 'var/sessions');
             break;
         case 'database':
         default:
             require_once 'models/common/common_session.php';
             $Session = new common_session();
             $Session->setCacheable(false);
             $result = session_set_save_handler(array(&$Session, 'open'), array(&$Session, 'close'), array(&$Session, 'read'), array(&$Session, 'write'), array(&$Session, 'destroy'), array(&$Session, 'gc'));
             if (!$result) {
                 die("Can't init session!");
             }
             break;
     }
     // disable no-cache headers
     //session_cache_limiter(0);
     //session_set_cookie_params(31536000);// = 3600 * 24 * 365
     session_start();
     //to be sure sessions are written before exit
     register_shutdown_function('session_write_close');
     //in PHP5.4 can be used this:
     //session_register_shutdown();
     if (!array_key_exists('active_pages', $_SESSION)) {
         $_SESSION['active_pages'] = array();
     }
     if (!array_key_exists('full_path', $_SESSION)) {
         $_SESSION['full_path'] = array();
     }
     if (array_key_exists('HTTPS', $_SERVER)) {
         $protocol = 'https';
     } else {
         $protocol = 'http';
     }
     $_SESSION['uri'] = "{$protocol}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
     $_SESSION['last_item'] = $_SESSION['history'][count($_SESSION['history']) - 1]['uri'];
     $_SESSION['orig'] = $_SERVER['REQUEST_URI'];
     $_SESSION['use_page_cache'] = $this->isPageCacheAllowed();
     // in the session history we store only new URIs and not the AJAX request (begin with /request/)
     // and don't store a popup
     if ($_SESSION['last_item'] != $_SESSION['uri'] && !preg_match('/^\\/(request)*(popup)*(popupimage)*(ajax)*\\//', $_SERVER['REQUEST_URI'])) {
         $_SESSION['history'][] = array('time' => time(), 'uri' => $_SESSION['uri']);
     }
     $_SESSION['last_diff'] = $_SESSION['last_item'];
 }
コード例 #2
0
ファイル: logs.php プロジェクト: AppChecker/onxshop
 /**
  * main action
  */
 public function mainAction()
 {
     require_once 'models/common/common_session.php';
     require_once 'models/common/common_session_archive.php';
     $Session = new common_session();
     $Session_archive = new common_session_archive();
     $Session->setCacheable(false);
     require_once 'models/client/client_customer.php';
     // filter
     if (isset($this->GET['filter'])) {
         $_SESSION['filter'] = $this->GET['filter'];
     }
     $filter = $_SESSION['filter'];
     if ($filter['active'] == 1) {
         $this->tpl->assign('ACTIVE_selected_1', "selected='selected'");
     } else {
         $this->tpl->assign('ACTIVE_selected_0', "selected='selected'");
     }
     if (!is_numeric($filter['customer_id']) || $filter['customer_id'] < 0) {
         $filter['customer_id'] = '';
     }
     $this->tpl->assign("FILTER", $filter);
     $session_ttl = round($Session->conf['ttl'] / 3600, 1);
     $this->tpl->assign('SESSION_TTL', $session_ttl);
     $Customer = new client_customer();
     $Customer->setCacheable(false);
     //pagination
     if (is_numeric($this->GET['limit_from']) && is_numeric($this->GET['limit_per_page'])) {
         $from = $this->GET['limit_from'];
         $per_page = $this->GET['limit_per_page'];
     } else {
         $from = 0;
         $per_page = 5;
     }
     $limit = "{$from},{$per_page}";
     if (is_numeric($filter['customer_id'])) {
         $where = "customer_id = {$filter['customer_id']}";
     } else {
         $where = '';
     }
     $count_active = $Session->count($where);
     $count_archive = $Session_archive->count($where);
     if ($filter['active'] == 1) {
         $sessions = $Session->listing($where, 'modified DESC', $limit);
         $count = $count_active;
     } else {
         $session_active = $Session->listing($where, 'modified DESC', $limit);
         //pagination must be handled differently
         if (count($session_active) < $per_page) {
             //start to show archive, but use different "from"
             $from_archived = $from + count($session_active) - $count_active;
             $session_archive = $Session_archive->listing($where, 'modified DESC', "{$from_archived},{$per_page}");
             $sessions = array_merge($session_active, $session_archive);
         } else {
             $sessions = $session_active;
         }
         $count = $count_active + $count_archive;
     }
     foreach ($sessions as $s) {
         $s['session_data'] = $this->unserialize_session_data($s['session_data']);
         if ($s['http_referer'] == '') {
             $link_block = "referer_na";
         } else {
             $link_block = "referer_link";
         }
         if (!is_array($s['session_data']['history'])) {
             $s['session_data']['history'] = array();
         }
         foreach ($s['session_data']['history'] as $history) {
             //temp
             if (!is_array($history)) {
                 $history = array('time' => 'n/a', 'uri' => $history);
             } else {
                 $history['time'] = strftime('%H:%M', $history['time']);
             }
             $this->tpl->assign('HISTORY', $history);
             $this->tpl->parse('content.item.history');
         }
         $s['time_diff'] = strtotime($s['modified']) - strtotime($s['created']);
         $s['time_diff'] = round($s['time_diff'] / 60);
         $s['created'] = strftime('%d/%m/%Y&nbsp;%H:%M', strtotime($s['created']));
         $s['modified'] = strftime('%d/%m/%Y&nbsp;%H:%M', strtotime($s['modified']));
         if ($s['customer_id'] > 0) {
             $this->tpl->assign('CUSTOMER', $Customer->detail($s['customer_id']));
         } else {
             $this->tpl->assign('CUSTOMER', '');
         }
         // show messages
         if (ONXSHOP_DEBUG_OUTPUT_FILE) {
             $messages_file = ONXSHOP_PROJECT_DIR . "var/log/messages/{$s['ip_address']}-{$s['session_id']}.log";
             if (file_exists($messages_file)) {
                 $s['messages'] = file_get_contents($messages_file);
             }
         }
         $this->tpl->assign('SESSION', $s);
         $this->tpl->parse("content.item.{$link_block}");
         if ($s['messages'] != '') {
             $this->tpl->parse('content.item.session_messages');
         }
         $this->tpl->parse('content.item');
     }
     //pagination
     //$link = "/backoffice/advanced/logs";
     $link = $_SERVER['REDIRECT_URL'];
     $_Onxshop_Request = new Onxshop_Request("component/pagination~limit_from={$from}:limit_per_page={$per_page}:count={$count}:link={$link}:option_show_all=1:option_per_page=1~");
     $this->tpl->assign('PAGINATION', $_Onxshop_Request->getContent());
     return true;
 }