1Mojolicious::Sessions(3U)ser Contributed Perl DocumentatiMoonjolicious::Sessions(3)
2
3
4

NAME

6       Mojolicious::Sessions - Session manager based on signed cookies
7

SYNOPSIS

9         use Mojolicious::Sessions;
10
11         my $sessions = Mojolicious::Sessions->new;
12         $sessions->cookie_name('myapp');
13         $sessions->default_expiration(86400);
14

DESCRIPTION

16       Mojolicious::Sessions manages sessions based on signed cookies for
17       Mojolicious. All data gets serialized with Mojo::JSON and stored Base64
18       encoded on the client-side, but is protected from unwanted changes with
19       a HMAC-SHA1 signature.
20

ATTRIBUTES

22       Mojolicious::Sessions implements the following attributes.
23
24   cookie_domain
25         my $domain = $sessions->cookie_domain;
26         $sessions  = $sessions->cookie_domain('.example.com');
27
28       Domain for session cookies, not defined by default.
29
30   cookie_name
31         my $name  = $sessions->cookie_name;
32         $sessions = $sessions->cookie_name('session');
33
34       Name for session cookies, defaults to "mojolicious".
35
36   cookie_path
37         my $path  = $sessions->cookie_path;
38         $sessions = $sessions->cookie_path('/foo');
39
40       Path for session cookies, defaults to "/".
41
42   default_expiration
43         my $time  = $sessions->default_expiration;
44         $sessions = $sessions->default_expiration(3600);
45
46       Default time for sessions to expire in seconds from now, defaults to
47       3600.  The expiration timeout gets refreshed for every request. Setting
48       the value to 0 will allow sessions to persist until the browser window
49       is closed, this can have security implications though. For more control
50       you can also use the "expiration" and "expires" session values.
51
52         # Expiration date in seconds from now (persists between requests)
53         $c->session(expiration => 604800);
54
55         # Expiration date as absolute epoch time (only valid for one request)
56         $c->session(expires => time + 604800);
57
58         # Delete whole session by setting an expiration date in the past
59         $c->session(expires => 1);
60
61   deserialize
62         my $cb    = $sessions->deserialize;
63         $sessions = $sessions->deserialize(sub {...});
64
65       A callback used to deserialize sessions, defaults to "j" in Mojo::JSON.
66
67         $sessions->deserialize(sub {
68           my $bytes = shift;
69           return {};
70         });
71
72   secure
73         my $bool  = $sessions->secure;
74         $sessions = $sessions->secure($bool);
75
76       Set the secure flag on all session cookies, so that browsers send them
77       only over HTTPS connections.
78
79   serialize
80         my $cb    = $sessions->serialize;
81         $sessions = $sessions->serialize(sub {...});
82
83       A callback used to serialize sessions, defaults to "encode_json" in
84       Mojo::JSON.
85
86         $sessions->serialize(sub {
87           my $hash = shift;
88           return '';
89         });
90

METHODS

92       Mojolicious::Sessions inherits all methods from Mojo::Base and
93       implements the following new ones.
94
95   load
96         $sessions->load(Mojolicious::Controller->new);
97
98       Load session data from signed cookie.
99
100   store
101         $sessions->store(Mojolicious::Controller->new);
102
103       Store session data in signed cookie.
104

SEE ALSO

106       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
107
108
109
110perl v5.28.0                      2018-05-08          Mojolicious::Sessions(3)
Impressum