NAME

Net::HTTPServer::Session

SYNOPSIS

Net::HTTPServer::Session handles server side client sessions

DESCRIPTION

Net::HTTPServer::Session provides a server side data store for client specific sessions. It uses a cookie stored on the browser to tell the server which session to restore to the user. This is modelled after the PHP session concept. The session is valid for 4 hours from the last time the cookie was sent.

EXAMPLES

sub pageHandler { my $request = shift;

my $session = $request->Session();

my $response = $request->Response();

# Logout
$session->Destroy() if $request->Env("logout");

$response->Print("<html><head><title>Hi there</title></head><body>");

# If the user specified a username on the URL, then save it.
if ($request->Env("username"))
{
    $session->Set("username",$request->Env("username"));
}

# If there is a saved username, then use it.
if ($session->Get("username"))
{
    $response->Print("Hello, ",$session->Get("username"),"!");
}
else
{
    $response->Print("Hello, stranger!");
}

$response->Print("</body></html>");

return $response;
}

The above would behave as follows:

http://server/page                - Hello, stranger!
http://server/page?username=Bob   - Hello, Bob!
http://server/page                - Hello, Bob!
http://server/page?username=Fred  - Hello, Fred!
http://server/page                - Hello, Fred!
http://server/page?logout=1       - Hello, stranger!
http://server/page                - Hello, stranger!

METHODS

Delete(var)

Delete the specified variable from the session.

Destroy()

Destroy the session. The server side data is deleted and the cookie will be expired.

Exists(var)

Returns if the specified variable exists in the sesion.

Get(var)

Return the value of the specified variable from the session if it exists, undef otherwise.

Set(var,value)

Store the specified value (scalar or reference to any Perl data structure) in the session.

AUTHOR

Ryan Eatmon

COPYRIGHT

Copyright (c) 2003-2005 Ryan Eatmon <reatmon@mail.com>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.