Apache-SessionManager
view release on metacpan or search on metacpan
SessionManager/cookpod.pod view on Meta::CPAN
F</usr/local/apache/cgi-application/CGI/Application/SessionManager.pm>.
The reason to for subclassing this is the benefits is creating a custom
"application super-class" from which which all your CGI applications would
inherit, instead of L<CGI::Application|CGI::Application>.
Then we write F<WebApp.pm> Application Module that inherit from our
super-class CGI::Application::SessionManager:
package WebApp;
use Data::Dumper;
use base 'CGI::Application::SessionManager';
sub setup {
my $self = shift;
$self->start_mode('mode1');
$self->mode_param('rm');
$self->run_modes(
'mode1' => 'do_session'
'mode2' => 'do_stuff',
'mode3' => 'do_more_stuff',
SessionManager/cookpod.pod view on Meta::CPAN
For example this is F</usr/local/apache/htdocs/plp/session.plp>:
<:
my $title = 'Session management with PLP';
:>
<HTML>
<HEAD>
<TITLE><: print $title :></TITLE>
<BODY>
<:
use Data::Dumper;
print "<H1>$title</H1>";
:>
<B>Session dump</B><PRE>
<:
print Dumper($session);
$session->{$$ . '-' . rand()} = rand;
:>
</PRE>
</BODY>
</HTML>
SessionManager/cookpod.pod view on Meta::CPAN
PerlSetVar SessionManagerStore File
PerlSetVar SessionManagerStoreArgs "Directory => /path/to/session/data"
PerlSetVar SessionManagerDebug 5
</FilesMatch>
</IfModule>
To test session you can use this simple CGI script:
#!/usr/bin/perl
use Data::Dumper ();
my $session = Apache::SessionManager::get_session(Apache->request);
$session->{$$ . '-' . rand()} = rand;
print "Content-type: text/html\n\n";
print '<PRE>' . Data::Dumper::Dumper($session) . '</PRE>';
Save it with a F<.cgi> extension (like F<session.cgi>) in the same directory
where you have F<.htaccess> and make it executable by web server.
=head1 USING Apache::SessionManager AND Apache::DBI
=head2 INTRODUCTION
This section describes how to use
L<Apache::SessionManager|Apache::SessionManager> with
t/lib/MyAuth.pm view on Meta::CPAN
$session->{'logged'} = 1;
# Redirect to original protected resource
$r->content_type('text/html');
$r->headers_out->{'Location'} = $session->{'redirect'};
return MP2 ? Apache::REDIRECT : Apache::Constants::REDIRECT;
}
sub verifiy_cred {
my %cred = @_;
#use Data::Dumper;
#print STDERR Dumper(\%cred);
# Check correct username and password
return 1 if ( $cred{'username'} eq 'foo' && $cred{'password'} eq 'baz' );
return 0;
}
1;
t/lib/PrintEnv.pm view on Meta::CPAN
package PrintEnv;
require 5.005;
use strict;
use Data::Dumper;
use vars qw($VERSION);
$VERSION = '0.2';
use mod_perl;
use constant MP2 => ($mod_perl::VERSION >= 1.99);
BEGIN {
# Test mod_perl version and use the appropriate components
if (MP2) {
t/lib/PrintEnv.pm view on Meta::CPAN
my $str;
# Main output
$str = <<EOM;
<HTML>
<HEAD><TITLE>mod_perl Apache::SessionManager test module</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF">
<CENTER><H1>mod_perl Apache::SessionManager test module</H1></CENTER>
EOM
$str .= '<PRE>' . Data::Dumper::Dumper($session) . '</PRE>';
# $str .= HashVariables($session,'<H2>Session Dump</H2>');
$str .= HashVariables(\%INC,'<H2>%INC</H2>');
$str .= HashVariables($r->subprocess_env,'<H2>Environment variables</H2>');
$str .= HashVariables(MP2 ? $r->headers_in() : { $r->headers_in() },'<H2>HTTP request headers</H2>');
$str .= "</BODY>\n</HTML>";
# set session value
$$session{rand()} = rand;
# Output code to client
t/lib/PrintEnvOO.pm view on Meta::CPAN
package PrintEnvOO;
require 5.005;
use strict;
use Data::Dumper;
use vars qw($VERSION);
$VERSION = '0.2';
use mod_perl;
use constant MP2 => ($mod_perl::VERSION >= 1.99);
BEGIN {
# Test mod_perl version and use the appropriate components
if (MP2) {
t/lib/PrintEnvOO.pm view on Meta::CPAN
</TABLE>
EOM
# Get CGI params
my $form = (MP2) ? { Vars } : { $r->args() };
# Delete session value (if any) OO interface
$r->delete_session_param($form->{delete_session_param});
# Get session values
$str .= '<PRE>' . Data::Dumper::Dumper($session) . '</PRE>';
# Get session values, OO interface I
$str .= '<PRE>' . Data::Dumper::Dumper($r->{'session'}) . '</PRE>';
# Get session values, OO interface II
$str .= '<PRE>' . "@{ [ $r->get_session_param ] }" . '</PRE>';
$str .= '<PRE>' . join(', ',$r->get_session_param) . '</PRE>';
# Get session values, OO interface II
my $param = $r->get_session_param('_session_id');
$str .= '<PRE>' . $param . '</PRE>';
# $str .= HashVariables($session,'<H2>Session Dump</H2>');
( run in 0.688 second using v1.01-cache-2.11-cpan-4d50c553e7e )