本文整理汇总了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();
}
示例2: isSessionStarted
/**
* {@inheritDoc}
*/
public function isSessionStarted()
{
if (!$this->session->isStarted()) {
$this->session->start();
}
return $this->session->isStarted();
}
示例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();
}
}
示例4: __construct
public function __construct(Mysql $db, Session $session)
{
$this->db = $db;
$this->session = $session;
if (!$this->session->isStarted()) {
$this->session->start();
}
}
示例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();
}
示例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();
}
}
示例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);
}
示例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!
}
}
示例9: start
/**
* {@inheritdoc}
*/
public function start()
{
parent::start();
if (!$this->has('_token')) {
$this->put('_token', str_random(40));
}
}
示例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;
}
示例11: indexAction
public function indexAction()
{
$session = new Session();
$session->start();
$user_session = $session->get('username');
return $this->render('goldtaskAppBundle:Default:index.html.twig');
}
示例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));
}
示例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();
};
}
示例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);
}
示例15: generateTokenString
/**
* Generate token string
*/
private function generateTokenString()
{
if ($this->session->isStarted() === false) {
$this->session->start();
}
return sha1($this->secret . $this->session->getId());
}