#! /usr/bin/perl use strict; use HTMLObject::Normal; use Apache::Session::Postgres; use HTMLObject::GetCookie; use HTMLObject::CGILib; #use cgi_lib; HTMLObject::GetCookie::GetCookies(); my $doc = HTMLObject::Normal->new(); use vars '%input'; #cgi_lib::ReadParse(*input); HTMLObject::CGILib::ReadParse(*input); my $sessionId = $HTMLObject::GetCookie::Cookies{'sessionId'}; my $command = $input{'command'}; my %s = {}; if ($command ne "logout" || ($command eq "logout" && length $sessionId > 0)) { eval { tie %s, 'Apache::Session::Postgres', $sessionId, { DataSource => 'dbi:Pg:dbname=sessions', UserName => 'postgres', Password => '', Commit => 1 }; }; } if ($@) { $doc->setTitle("Apache::Session Error!"); $doc->setFocus("body"); $doc->setCookie(name => "sessionId", expires => "Mon, 01-Jan-1999 00:00:00 GMT"); $doc->print("sessionId = '$sessionId' does not exist anymore!
Error='$@'."); $doc->display(); exit(1); } if ($command eq "logout") { if (length $sessionId > 0) { eval { tied(%s)->delete; }; if ($@) { $doc->setTitle("Apache::Session Error!"); $doc->setFocus("body"); $doc->setCookie(name => "sessionId", expires => "Mon, 01-Jan-1999 00:00:00 GMT"); $doc->print("Deleting Session info for id = '$sessionId' failed!
Error = '$@'."); $doc->display(); exit(1); } $doc->setTitle("Apache::Session LogOut"); $doc->setFocus("body"); $doc->setCookie(name => "sessionId", expires => "Mon, 01-Jan-1999 00:00:00 GMT"); $doc->print("You are logged out. Go here to work some more."); $doc->display(); exit(0); } else { $doc->setTitle("Apache::Session Error!"); $doc->setFocus("body"); $doc->print("You are already logged out and don't have a session going!
"); $doc->print("Go here to work some more."); $doc->display(); exit(0); } } my $id = $s{_session_id}; # this is an internal variable from the Apache::Session module. $doc->setTitle("Apache::Session test page"); $doc->setCookie(name => "sessionId", value => "$id"); $doc->setFocus("body"); $doc->print("foo = '".$s{foo}."'
\n"); $doc->print("baz = '".$s{baz}."'
\n"); $s{foo} = 'bar'; $s{baz} = ['tom', 'dick', 'harry']; untie %s; # present the link to delete this session. $doc->print("


Log Out\n"); $doc->display();