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


PHP Session::start方法代码示例

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


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

示例1: getSessionId

 /**
  * {@inheritdoc}
  */
 protected function getSessionId()
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->getId();
 }
开发者ID:jacobjjc,项目名称:PageKit-framework,代码行数:10,代码来源:SessionCsrfProvider.php

示例2: isSessionStarted

 /**
  * {@inheritDoc}
  */
 public function isSessionStarted()
 {
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     return $this->session->isStarted();
 }
开发者ID:focuslife,项目名称:v0.1,代码行数:10,代码来源:SymfonyHttpDriver.php

示例3: startSession

 /**
  * Starts the session if it does not exist.
  *
  * @return void
  */
 protected function startSession()
 {
     // Check that the session hasn't already been started
     if ($this->session->isStarted()) {
         $this->session->start();
     }
 }
开发者ID:Webapper,项目名称:silex-sentinel-service-provider,代码行数:12,代码来源:SilexSession.php

示例4: __construct

 public function __construct(Mysql $db, Session $session)
 {
     $this->db = $db;
     $this->session = $session;
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
 }
开发者ID:jorions,项目名称:acashop,代码行数:8,代码来源:LoginService.php

示例5: init

 /**
  * Initialize the Controller
  * Sets all attributes and starts the session
  *
  * @param $request
  * @param $em
  * @param $twig
  * @param $formFactory
  */
 public function init($request, $em, $twig, $formFactory)
 {
     $this->request = $request;
     $this->em = $em;
     $this->twig = $twig;
     $this->formFactory = $formFactory;
     $this->session = new Session();
     $this->session->start();
 }
开发者ID:easselin,项目名称:orchestra,代码行数:18,代码来源:Controller.php

示例6: __construct

 public function __construct(Mysql $db, Session $session, LoginService $login)
 {
     $this->db = $db;
     $this->session = $session;
     $this->login = $login;
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
 }
开发者ID:jorions,项目名称:acashop-OLD,代码行数:9,代码来源:ProfileService.php

示例7: __construct

 /**
  * Session constructor.
  *
  * @param string|null $namespace
  */
 public function __construct($namespace = null)
 {
     @session_start();
     $this->session = new SymfonySession(new PhpBridgeSessionStorage());
     if (!$this->session->isStarted()) {
         $this->session->start();
     }
     $this->setSessionValues($namespace);
 }
开发者ID:vmille,项目名称:TuleapRestApiBridge,代码行数:14,代码来源:Session.php

示例8: 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

示例9: start

 /**
  * {@inheritdoc}
  */
 public function start()
 {
     parent::start();
     if (!$this->has('_token')) {
         $this->put('_token', str_random(40));
     }
 }
开发者ID:trangunghoa,项目名称:l4cms,代码行数:10,代码来源:Store.php

示例10: initSession

function initSession()
{
    $storage = new NativeSessionStorage(['cookie_lifetime' => 3600, 'gc_probability' => 1, 'gc_divisor' => 1, 'gc_maxlifetime' => 10000], new NativeFileSessionHandler());
    $session = new Session($storage, new NamespacedAttributeBag());
    $session->start();
    return $session;
}
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:7,代码来源:init.php

示例11: indexAction

 public function indexAction()
 {
     $session = new Session();
     $session->start();
     $user_session = $session->get('username');
     return $this->render('goldtaskAppBundle:Default:index.html.twig');
 }
开发者ID:usharanimoturi,项目名称:goldtask,代码行数:7,代码来源:DefaultController.php

示例12: indexAction

 /**
  * @Route("/", name="homepage")
  */
 public function indexAction(Request $request)
 {
     //start session
     $session = new Session(new PhpBridgeSessionStorage());
     $session->start();
     $session->set('date', time());
     //get products from DB
     $products = $this->getDoctrine()->getRepository('AppBundle:Cart')->findAll();
     //get session products
     $sessionProducts = $session->get('products');
     $productArray = null;
     //if post save to db && session
     if ($request->isMethod('post')) {
         $postProduct = [$request->request->get('product')];
         if (!empty($sessionProducts)) {
             $productArray = array_merge($sessionProducts, $postProduct);
         } else {
             $productArray = $postProduct;
         }
         $productArray = array_unique($productArray);
     }
     $session->set('products', $productArray);
     // this helps create cookie for session
     $session->save();
     return $this->render('default/index.html.twig', array('sessionProducts' => $productArray, 'products' => $products));
 }
开发者ID:grzegab,项目名称:cart,代码行数:29,代码来源:DefaultController.php

示例13: register

 /**
  * @param Container $pimple A container instance
  */
 public function register(Container $pimple)
 {
     $pimple[SystemContainer::REQUEST] = function () {
         return Request::createFromGlobals();
     };
     $pimple[SystemContainer::SESSION] = function () {
         if ($this->mockSession) {
             $session = new Session(new MockArraySessionStorage());
         } else {
             $session = new Session();
         }
         $session->setName(sprintf('SID%s', mt_rand(1000, 9999)));
         $session->start();
         return $session;
     };
     $pimple[SystemContainer::TIME_PROVIDER] = function () {
         return new SystemTimeProvider();
     };
     $pimple[SystemContainer::EVENT_DISPATCHER] = function () {
         return new EventDispatcher();
     };
     $pimple[SystemContainer::LOGGER] = function () {
         return new NullLogger();
     };
 }
开发者ID:aarnaud,项目名称:lightSAML,代码行数:28,代码来源:SystemContainerProvider.php

示例14: CaptchaSecurityImages

 function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
 {
     $code = $this->generateCode($characters);
     /* font size will be 75% of the image height */
     $font_size = $height * 0.75;
     $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $background_color = imagecolorallocate($image, 255, 255, 255);
     $text_color = imagecolorallocate($image, 20, 40, 100);
     $noise_color = imagecolorallocate($image, 100, 120, 180);
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* create textbox and add text */
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* output captcha image to browser */
     $session = new Session();
     $session->start();
     $session->set('security_code', $code);
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
开发者ID:NickPolyder,项目名称:WebVillas-Symfony2Edition-,代码行数:31,代码来源:CaptchaSecurityImages.php

示例15: generateTokenString

 /**
  * Generate token string
  */
 private function generateTokenString()
 {
     if ($this->session->isStarted() === false) {
         $this->session->start();
     }
     return sha1($this->secret . $this->session->getId());
 }
开发者ID:suin,项目名称:symfony2-csrf-firewall-bundle,代码行数:10,代码来源:FirewallListener.php


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