當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。