DocumentRoot/cgi-bin/session/name.pl
DocumentRoot/cgi-bin/session/hobbies.pl
DocumentRoot/cgi-bin/session/job.pl
all belong to the web application /cgi-bin/session
/tmp/sessions/cgi-bin/session/session_dir
where the session_dir is different for each user
Session
$sob = Session->new()
open_session()
close_session()
name
may be added to a session by
$sob->{SESSION}{name} =
start_html()
end_html
submit()
start_form()
startform_for()
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>
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();
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();
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();