title: Sessions in ZF2
body: <p>Could you tell me how to properly use sessions in ZF2? So far I have this code:</p>
  
  <pre><code>"session" =&gt;
  [
      "remember_me_seconds" =&gt; 2419200, 
      "use_cookies" =&gt; true,
      "cookie_httponly" =&gt; true
  ]
  </code></pre>
  
  <p>That's the session config I copied from some post here on stackoverflow. Now should I put this code into module.config.php in each module that uses sessions or in the Application module?</p>
  
  <pre><code>public function onBootstrap(EventInterface $Event)
  {
      $Config = $Event-&gt;getApplication()-&gt;getServiceManager()-&gt;get('Configuration');
      $SessionConfig = new SessionConfig();
      $SessionConfig-&gt;setOptions($Config['session']);
      $SessionManager = new SessionManager($SessionConfig);
      $SessionManager-&gt;start();  
      Container::setDefaultManager($SessionManager);
  }
  </code></pre>
  
  <p>Same problem with the onBootstrap() method of the Module class. Should this code go into each module's Module class or just once into the Application's Module class? </p>
  
  <p>In both cases I have tried both approaches and I even tried putting this code into both modules at once, but the only thing I was able to accomplish was to set session variables in controller's constructor and then read them in actions/methods. I wasn't able to set a session variable in one action/method and then read it in another. If I remove the lines in which I set the variables in controller's constructor, I can no longer see these variables in the session. The session just behaves like it was created and deleted each time a page is requested.</p>
  
  <p>Am I missing something? Please don't link me to any resources on the internet, I have read them all and they're not really helpful. </p>