symfony2 session lifetime

后端 未结 3 579
灰色年华
灰色年华 2020-11-30 03:56

I had a problem with symfony2 session component. I set some data to session through session container like this:

$sess = $this->get( \'session\' );
$sess-         


        
相关标签:
3条回答
  • 2020-11-30 04:19

    In Symfony 2.3 I think the right answer is found in app/config/config.yml:

    framework:
        session:
            cookie_lifetime: 7200
            gc_maxlifetime: 3600
    

    GC (garbage collection) will be reset every time the server is hit, meaning if the user is active, he'll have 3600 to continue working. The cookie_lifetime will force the user to log out in its limit. In this example, the user will have one hour to be inactive and will be forced out in 2 hours.

    0 讨论(0)
  • 2020-11-30 04:39

    To work comfortably you can set in dev environment a cookie_lifetime to 0, it means the cookie expires when the browser is closed.

    File: config_dev.php

      framework:
            session:
                cookie_lifetime: 0
    
    0 讨论(0)
  • 2020-11-30 04:44

    You can set the session expiration time in your config file under the framework section. Mine looks like this:

    config.yml

    framework:
      secret:        %secret%
      charset:       UTF-8
      error_handler: null
      csrf_protection:
          enabled: true
      router:        { resource: "%kernel.root_dir%/config/routing.yml" }
      validation:    { enabled: true, annotations: true }
      templating:    { engines: ['twig'] } #assets_version: SomeVersionScheme
      session:
          default_locale: %locale%
          cookie_lifetime: 3600 // was "lifetime" but deprecated
          auto_start:     true
    

    You can change the framework.session.lifetime value to anything you'd like, in seconds (it defaults to 3600, or 1 hour).

    Reference here.

    0 讨论(0)
提交回复
热议问题