CGI-Session
view release on metacpan or search on metacpan
lib/CGI/Session.pm view on Meta::CPAN
=head2 dump()
Returns a dump of the session object. Useful for debugging purposes only.
=head2 header()
A wrapper for C<CGI>'s header() method. Calling this method
is equivalent to something like this:
$cookie = CGI::Cookie->new(-name=>$session->name, -value=>$session->id);
print $cgi->header(-cookie=>$cookie, @_);
You can minimize the above into:
print $session->header();
It will retrieve the name of the session cookie from C<$session->name()> which defaults to C<$CGI::Session::NAME>. If you want to use a different name for your session cookie, do something like this before creating session object:
CGI::Session->name("MY_SID");
$session = CGI::Session->new(undef, $cgi, \%attrs);
lib/CGI/Session.pm view on Meta::CPAN
This document is also available in Japanese.
=over 4
=item o
Translation based on 4.14: http://digit.que.ne.jp/work/index.cgi?Perldoc/ja
=item o
Translation based on 3.11, including Cookbook and Tutorial: http://perldoc.jp/docs/modules/CGI-Session-3.11/
=back
=head1 CREDITS
CGI::Session evolved to what it is today with the help of following developers. The list doesn't follow any strict order, but somewhat chronological. Specifics can be found in F<Changes> file
=over 4
=item Andy Lester
lib/CGI/Session.pm view on Meta::CPAN
=item *
L<CGI::Session::Tutorial|CGI::Session::Tutorial> - extended CGI::Session manual. Also includes library architecture and driver specifications.
=item *
We also provide mailing lists for CGI::Session users. To subscribe to the list
or browse the archives visit
https://lists.sourceforge.net/lists/listinfo/cgi-session-user
=item * B<RFC 2109> - The primary spec for cookie handing in use, defining the "Cookie:" and "Set-Cookie:" HTTP headers.
Available at L<http://www.ietf.org/rfc/rfc2109.txt>. A newer spec, RFC 2965 is meant to obsolete it with "Set-Cookie2"
and "Cookie2" headers, but even of 2008, the newer spec is not widely supported. See L<http://www.ietf.org/rfc/rfc2965.txt>
=item *
L<Apache::Session|Apache::Session> - an alternative to CGI::Session.
=back
=cut
1;
lib/CGI/Session/Tutorial.pm view on Meta::CPAN
=pod
=head1 NAME
CGI::Session::Tutorial - Extended CGI::Session manual
=head1 STATE MAINTENANCE OVERVIEW
Since HTTP is a stateless protocol, each subsequent click to a web site is treated as new request by the Web server. The server does not relate a visit with a previous one, thus all the state information from the previous requests are lost. This make...
For our rescue come such technologies as I<HTTP Cookies> and I<QUERY_STRING>s that help us save the users' session for a certain period. Since I<HTTP Cookies> and I<QUERY_STRING>s alone cannot take us too far (B<RFC 2965, Section 5, "Implementation L...
Before we discuss this library, let's look at some alternative solutions.
=head2 COOKIE
Cookie is a piece of text-information that a web server is entitled to place in the user's hard disk, assuming a user agent (such as Internet Explorer, Mozilla, etc) is compatible with the specification. After the cookie is placed, user agents are re...
Although I<HTTP Cookies> seem to be promising solution for the statelessness of HTTP, they do carry certain limitations, such as limited number of cookies per domain and per user agent and limited size on each cookie. User Agents are required to stor...
=head2 QUERY STRING
Query string is a string appended to URL following a question mark (?) such as:
http://my.dot.com/login.cgi?user=sherzodr;password=top-secret
As you probably guessed, it can also help you pass state information from a click to another, but how secure is it do you think, considering these URLs tend to get cached by most of the user agents and also logged in the servers access log, to which ...
=head2 HIDDEN FIELDS
Hidden field is another alternative to using query strings and they come in two flavors: hidden fields used in POST methods and the ones in GET. The ones used in GET methods will turn into a true query strings once submitted, so all the disadvantages...
Query strings and hidden fields are also lost easily by closing the browser, or by clicking the browser's "Back" button.
=head2 SERVER SIDE SESSION MANAGEMENT
This technique is built upon the aforementioned technologies plus a server-side storage device, which saves the state data on the server side. Each session has a unique id associated with the data in the server. This id is also associated with the us...
Advantages:
=over 4
=item *
We no longer need to depend on User Agent constraints in cookie size.
=item *
Sensitive data no longer need to be traveling across the network at each request (which is the case with query strings, cookies and hidden fields). The only thing that travels is the unique id generated for the session (B<5767393932698093d0b75ef61437...
=item *
User will not have sensitive data stored in his/her computer in unsecured file (which is a cookie file).
=item *
It's possible to handle very big and even complex data structures transparently (which I<HTTP Cookies> do not handle).
=back
That's what CGI::Session is all about - implementing server side session management. Now is a good time to get feet wet.
=head1 PROGRAMMING STYLE
Server side session management system might be seeming awfully convoluted if you have never dealt with it. Fortunately, with L<CGI::Session|CGI::Session> all the complexity is handled by the library transparently. This section of the manual can be tr...
All applications making use of server side session management rely on the following pattern of operation regardless of the way the system is implemented:
lib/CGI/Session/Tutorial.pm view on Meta::CPAN
C<name()> returns C<CGISESSID> by default. If you prefer a different cookie name, you can change it as easily too, but you have to do it before CGI::Session object is created:
CGI::Session->name("SID");
$session = CGI::Session->new();
Baking the cookie wasn't too difficult, was it? But there is an even easier way to send a cookie using CGI::Session:
print $session->header();
The above will create the cookie using L<CGI::Cookie|CGI::Cookie> and will return proper http headers using L<CGI.pm|CGI>'s L<CGI|CGI/header()> method. Any arguments to L<CGI::Session|CGI::Session/header()> will be passed to L<CGI::header()|CGI/heade...
Of course, this method of initialization will only work if client is accepting cookies. If not you would have to pass session ID in each URL of your application as QUERY_STRING. For CGI::Session to detect it the name of the parameter should be the sa...
printf ("<a href=\"$ENV{SCRIPT_NAME}?%s=%s\">click me</a>", $session->name, $session->id);
If you already have session id to be initialized you may pass it as the only argument, or the second argument of multi-argument syntax:
$session = CGI::Session->new( $sid );
$session = CGI::Session->new( "serializer:freezethaw", $sid );
$session = CGI::Session->new( "driver:mysql", $sid, {Handle=>$dbh} );
( run in 0.675 second using v1.01-cache-2.11-cpan-e9199f4ba4c )