Net::H...ession(3pm)
π Net::HTTPServer::Session β bestie, your server finally remembers people π
okay so this is Net::HTTPServer::Session, a little Perl module from the User Contributed Perl Documentation corner of your 3pm man pages, and it's literally here to give your HTTP server side client sessions. yes. server-side memory. for each person. it's giving "the server actually knows who you are" energy β¨
β¨ NAME β¨
Net::HTTPServer::Session β HTTP server side client session, periodt π
πΈ SYNOPSIS πΈ
Net::HTTPServer::Session handles server side client sessions. that's the whole vibe, no notes π«Ά
π¦ DESCRIPTION π¦
okay so here's the tea π β Net::HTTPServer::Session gives you a server side data store for sessions that belong to specific clients. it does this by dropping a cookie on the browser, and that cookie is how the server knows which session to restore to the user when they come back. iykyk.
this is modelled after the PHP session concept, bestie, so if you've ever touched PHP sessions this will feel like coming home π
and here's the important bit, no cap: the session is valid for 4 hours from the last time the cookie was sent. so it's a rolling window, not a hard timer from when it was born. lowkey generous of it β°
π EXAMPLES π
here's a whole pageHandler sub that shows the entire lifecycle β login, logout, remembering your fave person, all of it π
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;
}
and the above would behave exactly like this, watch the glow-up happen in real time π:
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!
see how it just remembers? main character energy fr fr ππ
π METHODS π
π Delete(var)
delete the specified variable from the session. bye bestie, we don't know her anymore π
π Destroy()
destroy the session. and when we say destroy we mean it β the server side data is deleted and the cookie will be expired. full send. it's over. no crumbs left π
π§ Exists(var)
returns whether the specified variable exists in the session. a simple "does this thing live here or not" vibe check β
β Get(var)
return the value of the specified variable from the session if it exists, and undef otherwise. no value? no problem, you just get undef π«Ά
πΈ Set(var,value)
store the specified value in the session β and it can be a scalar or a reference to any Perl data structure. hashes, arrays, nested chaos, whatever you want, it holds it all π
π 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.
ngl if you're out here storing sessions server-side with a cookie and a four hour rolling window, you're doing amazing sweetie π«Ά
so that's the whole page, bestie β perl v5.36.0, dated 2022-12-06, straight from the Net::HTTPServer::Session(3pm) man page. go forth and remember your users, and slay π
β¨π
π¦ where this page comes from
- debian bookworm: libnet-httpserver-perl 1.1.1-4 Β· Artistic-1.0-Perl
- debian trixie: libnet-httpserver-perl 1.1.1-4 Β· Artistic-1.0-Perl
- ubuntu noble: libnet-httpserver-perl 1.1.1-4 Β· Artistic-1.0-Perl
- ubuntu resolute: libnet-httpserver-perl 1.1.1-4 Β· Artistic-1.0-Perl
- ubuntu stonking: libnet-httpserver-perl 1.1.1-4 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms