Skip to content

Commit

Permalink
better examples for session expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 19, 2012
1 parent 351e58c commit b3a8efc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -906,10 +906,13 @@ and stored in C<HMAC-SHA1> signed cookies. Note that cookies usually have a
my $foo = $c->session->{foo};
delete $c->session->{foo};
# Expire a week from now (epoch seconds from now)
# Expiration date in epoch seconds from now (persists between requests)
$c->session(expiration => 604800);
# Expire a long long time ago (absolute time in epoch seconds)
# Expiration date as absolute epoch time (only valid for one request)
$c->session(expires => time + 604800);
# Delete whole session by setting an expiration date in the past
$c->session(expires => 1);
=head2 C<signed_cookie>
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Guides/Growing.pod
Expand Up @@ -355,13 +355,13 @@ secure and can be changed at any time to invalidate all existing sessions.
$self->session(user => 'sri');
my $user = $self->session('user');

By default all sessions expire after one hour, for more control you can also
use the C<expiration> session value.
By default all sessions expire after one hour, for more control you can use
the C<expiration> session value to set an expiration date in seconds from now.

$self->session(expiration => 3600);

And the whole session can be deleted by using the C<expires> session value to
set an expiration date in the past.
set an absolute expiration date in the past.

$self->session(expires => 1);

Expand Down
7 changes: 5 additions & 2 deletions lib/Mojolicious/Sessions.pm
Expand Up @@ -127,10 +127,13 @@ will allow sessions to persist until the browser window is closed, this can
have security implications though. For more control you can also use the
C<expiration> and C<expires> session values.
# Expire a week from now (epoch seconds from now)
# Expiration date in epoch seconds from now (persists between requests)
$c->session(expiration => 604800);
# Expire a long long time ago (absolute time in epoch seconds)
# Expiration date as absolute epoch time (only valid for one request)
$c->session(expires => time + 604800);
# Delete whole session by setting an expiration date in the past
$c->session(expires => 1);
=head2 C<secure>
Expand Down

0 comments on commit b3a8efc

Please sign in to comment.