Home : Documentation : 1.3.6 documentation : HTML::Embperl
Google Web perl.apache.org

 
Home
 
Features
 
Introduction
 
Documentation
 
README
 
README.v2
 
Configuration
 
Embperl
 
Embperl::Object
 
Embperl::Form::Validate
 
Embperl::Syntax
 
Embperl::Recipe
 
Embperl::Mail
 
1.3.6 documentation
 
HTML::Embperl
 
HTML::EmbperlObject
 
HTML::Embperl::Mail
 
HTML::Embperl::Session
 
Tips & Tricks
 
FAQ
 
DBIx::Recordset
 
Installation
 
Download
 
Support
 
Changes
 
Wiki
 
More infos
 
Add info about Embperl
 
Login

    Stable 2.4.0
    Beta 2.5.0_3
Support the development of Embperl! More...
Session handling
[ << Prev: Predefined variables ] [ Content ] [ Next: (Safe-)Namespaces and opcode restrictions >> ]

From 1.2b1 and higher Embperl is able to handle per user sessions for you. You can store any data in the %udat hash and if the same user requests an Embperl document again, you will see the same values in that hash again.

From 1.2b2 and higher Embperl is able to handle per module/page persistent data for you. You can store any data in the %mdat hash and if any request comes to the same Embperl document, you will see the same values in that hash again.

Session handling has changed from 1.3.3 to 1.3.4 and 2.0b3 to 2.0b4. You must either install Apache::SessionX or set

    PerlSetEnv EMBPERL_SESSION_HANDLER_CLASS "HTML::Embperl::Session"

to get the old behaviour. If you have Apache::SessionX installed, you don't have to make addtional configuration, otherwise you must do the following things. You are also able to override the Apache::SessionX defaults, by using the following parameters:

To configure Embperl to do session management for you, you must have installed Apache::Session (1.53 or higher) and tell Embperl which storage and locker classes you would like to use for Apache::Session. This is done by setting the environment variable EMBPERL_SESSION_CLASSES. If you want to use a MySQL database for storing your sessions, you may have a startup.pl for your httpd which looks like this:

 BEGIN
    {
    $ENV{EMBPERL_SESSION_CLASSES} = "MySQL Semaphore" ;
    $ENV{EMBPERL_SESSION_ARGS}    = "DataSource=dbi:mysql:session UserName=test" ;
    } ;

 use HTML::Embperl ;

or you may put this in the httpd/srm.conf:

 PerlSetEnv EMBPERL_SESSION_CLASSES "MySQL Semaphore"
 PerlSetEnv EMBPERL_SESSION_ARGS "DataSource=dbi:mysql:session UserName=test"
 PerlModule HTML::Embperl ;

Refer to the Apache::Session docs (e.g. Apache::Session::Store::MySQL) on how to setup your database tables.

EMBPERL_SESSION_ARGS is a space separated list of name/value pairs, which gives additional arguments for Apache::Session classes.

Here is an example for using a filesystem based storage:

PerlSetEnv EMBPERL_SESSION_CLASSES "File Semaphore" PerlSetEnv EMBPERL_SESSION_ARGS "Directory=/path/to/your/sessions"

Refer to the Apache::Session docs to find out which other storage/locker methods are available.

EMBPERL_SESSION_CLASSES can (optionally) take two more classnames, which specify the class for serialization (Default: Storable) and for generating the id (Default: MD5).

NOTE: The above configuration works only with Apache::Session 1.52 and Embperl 1.3b5 or above. Older versions of Embperl only support Apache::Session 1.0x, which has different parameters for EMBPERL_SESSION_CLASSES (e.g. $ENV{EMBPERL_SESSION_CLASSES} = "DBIStore SysVSemaphoreLocker" ; ) Apache::Session 1.0x still works with this Embperl version.

Now you are able to use the %udat and %mdat hashes for your user/module sessions. As long as you don't touch %udat or %mdat, Embperl will not create any session, and Apache::Session is not loaded. As soon as you store any value to %udat, Embperl will create a new session and send a cookie to the browser to maintain its id, while the data is stored by Apache::Session. (Further version may also be able to use URL rewriting for storing the id). When you modify %mdat, Embperl will store the data via Apache::Session and retrieve it when the next request comes to the same page.



Functions/Methods for session handlingtop


HTML::Embperl::Req::SetupSession ($req_rec, $Inputfile) [1.3b6+]top

This can be used from a script that will later call HTML::Embperl::Execute to preset the session so it's available to the calling script.

 

$req_rec

 

Apache request record when running under mod_perl, undef otherwise.

 

$Inputfile

 

Name of file that will be later processed by Embperl. It is used to setup %mdat. If you don't pass the $Inputfile, %mdat is not setup.

Returns a reference to %udat or, if call in an array context, a reference to %udat and %mdat. See also CleanupSession.



HTML::Embperl::Req::GetSession / $r -> GetSession [1.3b6+]top

Returns a reference to %udat or, if called in an array context, a reference to %udat and %mdat. This could be used by modules that are called from inside an Embperl page, where the session management is already setup. If called as a method $r must be a HTML::Embperl::Req object, which is passed as first parameter to every Embperl page in @_ .



HTML::Embperl::Req::CleanupSession / $r -> CleanupSession [1.3b6+]top

Must be called at the end of a script by scripts that use SetupSession, but do not call HTML::Embperl::Execute. If called as a method $r must be a HTML::Embperl::Req object, which is passed as first parameter to every Embperl page in @_ .



HTML::Embperl::Req::DeleteSession / $r -> DeleteSession [1.3b6+]top

Deletes the session data and removes the cookie from the browser. If called as a method $r must be a HTML::Embperl::Req object, which is passed as first parameter to every Embperl page in @_ .



HTML::Embperl::Req::RefreshSession / $r -> RefreshSession [1.3b6+]top

Triggers a resend of the cookie. Normaly the cookie is only send the first time. If called as a method $r must be a HTML::Embperl::Req object, which is passed as first parameter to every Embperl page in @_ .



HTML::Embperl::Req::SetSessionCookie / $r -> SetSessionCookie [1.3b7+]top

Must be called by scripts that use SetupSession, but do not call HTML::Embperl::Execute. This is neccessary to set the cookie for the session id, in case a new session is created, which is normaly done by HTML::Embperl::Execute. If called as a method $r must be a HTML::Embperl::Req object, which is passed as first parameter to every Embperl page in @_ .


[ << Prev: Predefined variables ] [ Content ] [ Next: (Safe-)Namespaces and opcode restrictions >> ]

© 1997-2012 Gerald Richter / ecos gmbh