Konstrukt::Session - Session management (Cookies/Session)
The user will automatically get a session and you (as a plugin developer) can access the session object easily like this:
$Konstrukt::Session->method();
The following methods are available:
$Konstrukt::Session->activated(); #returns true if the session management is activated $sid = $Konstrukt::Session->session_id($key); #get session id $Konstrukt::Session->set($key => $value); #set value $boolean = $Konstrukt::Session->exists($key); #does this key exist? $value = $Konstrukt::Session->get($key); #get value @keys = $Konstrukt::Session->keys(); #get all keys $Konstrukt::Session->delete($key); #delete specified key $Konstrukt::Session->clear(); #clear all keys
That's currently exactly what the CPAN-module Session offers, since Session currently is the only method of handling sessions internally. As Session uses Apache::Session and Apache::Session::Flex internally, you might also want to take a look at those.
Currently only the MySQL backend has been tested so the settings may not be apropriate to cover all backends offered by Apache::Session.
This module provides easy session management for your plugins/websites.
To use the session management it must be activated in your konstrukt.settings (it's deactivated by default).
#Session management session/use 1 #default: 0 #backend module. probably all Apache::Session backends possible, but not tested session/store MySQL #dbi source. will default to your Konstrukt::DBI settings, when not specified session/source dbi:mysql:database:host session/user user session/pass pass session/timeout 60 #default: delete sessions that haven't been used for 60 minutes #session/table session #currently unsupported #only for backend store "File". Note: The path does _not_ relate to your document root! session/directory /tmp/sessions #default: save sessions in dir /tmp/sessions. you have to create that dir! #only for backend store "DB_file". Note: The path does _not_ relate to your document root! session/file /tmp/sessions #default: save sessions in file /tmp/sessions #show error message, if session could not be loaded or silently create a new one session/show_error 1
Constructor of this class
Initialization of this class
Parameters: none
Initializes the backend according the settings (e.g. create tables).
Parameters:
none
Returns true if the session management is activated and ready to use.
Creates a new session and sets an SID-cookie
Sets a timestamp for the session and sets it as an attribute of this object
$session - The session object
Deletes old sessions from the database
Wrapper methods for the usual methods of the session backend. For more indormation take a look at e.g. Session.
(Implemented using AUTOLOAD.)
Methods
set('key', 'value') - Set a value
get('key') - Retrieve a value
remove('key') - Delete a key
clear() - Delete all keys
session_id() - Returns the current session id
exists('key') - Returns true if the key exists
keys() - Returns an array with the keys within the session
delete() - Delete the session
release() - Release the session
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software. It is distributed under the same terms as Perl itself.
Session, Apache::Session, Apache::Session::Flex, Konstrukt
To install Konstrukt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Konstrukt
CPAN shell
perl -MCPAN -e shell install Konstrukt
For more information on module installation, please visit the detailed CPAN module installation guide.