Name
CGI::Session — CGI session class
Synopsis
CGI::Session
maintains a persistent session between
HTTP accesses. Session information is represented by string to string
mapping. Session information can be stored via the user-defined
database class.
Required Library
require ‘cgi/session’
Example
request 'cgi/session' cgi = CGI::new("html3") s = CGI::Session(cgi) if s["last_modified"] # previously saved data t = s["last_modified"].to_i else t = Time.now.to_i # save data to session database s["last_modified"] = t.to_s end # ... continues ...
Class Methods
CGI::Session::new(
cgi
[,
option
])
Starts a new CGI session and returns the corresponding
CGI::Session
object.option
may be an option hash specifying one or more of the following:
Key |
Function |
Default value |
session_key |
Key name holding the session ID |
_session_id |
session_id |
Unique session ID |
Generated automatically |
new_session |
If |
false |
database_manager |
Database manager class for storing session data |
CGI::Session::FileStore |
An option hash can specify options when
creating the database manager object. The default database manager
class (CGI::Session::FileStore
) recognizes the
following options:
Key |
Function |
Default value |
tmpdir |
Directory for temporary files |
/tmp |
prefix |
Prefix for temporary files |
None |
Methods for Database Manager
Database manager object should have following methods:
initialize(
session
[,
options
])
Initializes the database.
session
is aCGI::Session
object.options
is an option ...
Get Ruby in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.