logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Net::HTTPServer::Session - HTTP server side client session

Author

       Ryan Eatmon

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.

Name

       Net::HTTPServer::Session - HTTP server side client session

Synopsis

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

See Also