PageKit uses a subclass of Apache::SessionX to provide sessions. It sets a cookie named pkit_session_id with an expiration of session_expires, if applicable.

To access the session, use

    # gets hash tied to Session
    my $session = $model->session;
    # gets session value
    my $count = $session->{'count'};
    # sets session value
    $session->{'count'} = $count;

PageKit takes care of opening and closing sessions. Note that sessions are only created when something is written to session hash.


Because of the way Apache::SessionX works, the session only gets saved if top level element in the tied hash gets changed.

    # session will not be saved, if 'foo' was already in $session.
    my $session = $model->session;
    $session->{'foo'}->{'bar'} = 1;

    # session will be saved
    my $session = $model->session;
    $session->{'foo'}->{'bar'} = 1;
    # since 'baz' is top level element and is assigned, session will be saved
    $session->{'baz'} = 1;

To store information during a request, use the pnotes method.

As of PageKit 1.05, there is support for associating sessions with authentication. The associated session ID may be specified by the second argument returned my pkit_auth_session_key. When a user logs in, their current session may be merged with the session stored with their user ID. To override the default behavior, use the pkit_merge_sessions hook.

As of PageKit 1.08, there is support for page based sessions.