Session management from Perl Session module

Session.pm

Web application

Session object

Form information

Example getting info across multiple pages

Start HTML page


<html> <head>
<title>Session example</title>
</head>

<body>
<h1>Session example</h1>

<form action="/cgi-bin/session/name.pl" method="post">
Name:
<input type="textfield" name="name">
<br>
<input type="submit">

</form>
</body></html>

Example

First script


#!/usr/bin/perl

use vars qw($ob);

use Session;

local $ob = Session->new();

$ob->open_session(0);

# extract form name data
$name = $ob->param("name");

# add name to session
$ob->{SESSION}{name} = $name;

print $ob->header(),
    $ob->start_html('Hobby', 'Jan Newmarch');

print "Hi $name, please select a hobby\n";

print $ob->startform_for('hobbies.pl');
print $ob->popup_menu(-name=>'hobby',
		      -values=>['tennis','chess','eating','dancing']), "\n";
print $ob->submit();
print $ob->end_form();
print $ob->end_html;

$ob->close_session();

Example

Second script


#!/usr/bin/perl

use vars qw($ob);

use Session;

local $ob = Session->new();

$ob->open_session(0);

# extract form name data
$hobby = $ob->param('hobby');

# add hobby to session
$ob->{SESSION}{hobby} = $hobby;

# extract name from session
$name = $ob->{SESSION}{name};

print $ob->header(),
    $ob->start_html('Job', 'Jan Newmarch');

print "Hi $name, please select a job\n";

print $ob->startform_for('results.pl');
print $ob->popup_menu(-name=>'job',
		-values=>['teacher','plumber','actor','chef']), "\n";
print $ob->submit();
print $ob->end_form();

print $ob->end_html;

$ob->close_session();

Example

Third script


#!/usr/bin/perl

use vars qw($ob);

use Session;

local $ob = Session->new();

$ob->open_session(0);

# extract job from form
$job = $ob->param('job');

# extract name, hobby from session
$name = $ob->{SESSION}{name};
$hobby = $ob->{SESSION}{hobby};

print $ob->header(),
    $ob->start_html('Result', 'Jan Newmarch');

print "Your name is $name\n<br> Your hoby is $hobby\n<br> Your job is $job\n";

print $ob->end_html;

$ob->close_session();

Jan Newmarch (http://pandonia.canberra.edu.au)
jan@ise.canberra.edu.au
Last modified: Tue Aug 22 14:20:44 EST 2000
Copyright ©Jan Newmarch