当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::getMetadataBag方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\Session\Session::getMetadataBag方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getMetadataBag方法的具体用法?PHP Session::getMetadataBag怎么用?PHP Session::getMetadataBag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\Session\Session的用法示例。


在下文中一共展示了Session::getMetadataBag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initializeSession

 /**
  * Initialize the session.
  *
  * This is something you might want to override in your controller so you can
  * redirect to a page with a message about being logged out after detecting the session has expired.
  *
  * @var int $session_expiration Session Expiration in seconds
  */
 protected function initializeSession($session_expiration = null)
 {
     /**
      * Setup the session with cookie expiration of one week. This will
      * allow the session to persist even if the browser window is closed.
      * The session expiration will still be respected (default 1 hour).
      */
     $this->session = new Session(new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage(['cookie_lifetime' => 604800]));
     $this->config->load('config');
     // Should session cookie be http only? Default true to reduce XSS attack vector.
     $session_cookie_httponly = (bool) $this->config->get('session_cookie_httponly', true);
     ini_set('session.cookie_httponly', $session_cookie_httponly);
     // We need a unique session name for this app. Let's use last 10 characters the file path's sha1 hash.
     try {
         $this->session->setName('TSAPP' . substr(sha1(__FILE__), -10));
         $this->session->start();
         // Default session expiration 1 hour.
         // Can be overridden in method param or by setting session_expiration in config.php
         $session_expiration = !empty($session_expiration) ? $session_expiration : $this->config->get('session_expiration', 3600);
         // Is this session too old?
         if (time() - $this->session->getMetadataBag()->getLastUsed() > $session_expiration) {
             $this->session->invalidate();
         }
     } catch (\LogicException $e) {
         // Session already active, can't change it now!
     }
 }
开发者ID:werx,项目名称:core,代码行数:35,代码来源:Controller.php

示例2: checkSession

 /**
  * Função para validar a sessão
  *
  * @param Session $session
  * @return bool
  */
 public function checkSession(Session $session)
 {
     $logger = $this->get('logger');
     $session->getMetadataBag()->getCreated();
     $session->getMetadataBag()->getLastUsed();
     if (time() - $session->getMetadataBag()->getLastUsed() > $this->maxIdleTime) {
         $session->invalidate();
         $logger->error("Sessão inválida:\n" . $session->getId());
         //throw new SessionExpired(); // direciona para a página de sessão expirada
         return false;
     } else {
         return true;
     }
 }
开发者ID:mistercomputer,项目名称:cacic,代码行数:20,代码来源:NeoController.php


注:本文中的Symfony\Component\HttpFoundation\Session\Session::getMetadataBag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。