Net::HTTPServer::Session(3pm)

Net::HTTPServer::Session3pm

Http server side client session

Usage

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

Overview

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.

Releases

7 releases since Debian 7 (Wheezy); the text changed 3 times.

  1. 7
  2. 8–9
  3. 10–11
  4. 12–13

Author

Ryan Eatmon

From libnet-httpserver-perl 1.1.1-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.