3

I'm starting session like this:

$session = new Session();
$session->start();

Browsing documentation I found the method that returns lifetime of the session. Default Symfony 2.3 session time is 3600s. Is there a method that will return a current session time? (for instance session lasts for 10 minutes so I will get 600s). I haven't found anything like this in the documentation.

Or is there a way to manually count this time and carry this value through pages during the session?

Pan Panam
  • 71
  • 5

1 Answers1

4

Sure you can.

    $session = $this->get('session'); //you can get session from service container. no need for creating new instance.

// MetadataBag is what you're looking for
$sessionBag = $session->getMetadataBag();

// Here we go...
var_dump($sessionBag->getCreated());
var_dump($sessionBag->getLastUsed());

You may want to use created oflastUsed depending or your needs. created is when the session was initialized (first page request of user), while lastUsed is the latest of course. But since you're saying something about session lifetime you may want to use the second one, because that's the point of time where the lifetime is relative to.

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64