CGI-kSession

 view release on metacpan or  search on metacpan

example/eg2.cgi  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use CGI::kSession;
use CGI::Cookie;

    my $cgi = new CGI;
    my $last_sid = $cgi->param("SID");
    my $c = new CGI::Cookie(-name=>'SID',-value=>$last_sid);
    my ($id, $key, $value);

    my $s = new CGI::kSession(path=>"/tmp/");

    print $cgi->header(-cookie=>$c);

    print $cgi->start_html();

    if ($last_sid) {
        # note: the following I used for mozilla - your mileage may vary
        my $cookie_sid = (split/[=;]/, (fetch CGI::Cookie)->{SID})[1];

        if ($cookie_sid) {
            print "<b>We are now reading from the cookie:</b><p>";
            $id = $s->id($cookie_sid);
            $s->start($cookie_sid);
            print "The cookie's id: $cookie_sid<br>";
            print "Here's the test_value: ".$s->get("test_key")."<br>";
        } else {
            print "<b>We are now reading from the URL parameters:</b><p>";
            $id = $s->id($last_sid);

kSession.pm  view on Meta::CPAN

=item $s = new CGI::kSession();

The constructor, this starts the ball rolling. It can take the following hash-style parameters:

	lifetime - 	how long the session lasts, in seconds
	path	 -	the directory where you want to store your session files
	id	 -	if you want to give the session a non-random name, use this parameter as well

=item $s->start();

This creates a session or resumes an old one (could be used in conjunction with something like HTTP::Cookie). This will return '1' if this is a new session, and '0' if it's resuming an old one. If you defined no values in the 'new()' call, then the s...

=item $s->save_path();

Save the session path or, without an argument, return the current session path. Used with an argument, this performs the same thing as the 'path' parameter in the constructor.

=item $s->id();

If the session id exists, this will return the current session id - useful if you want to maintain state with a cookie! If you pass a parameter, it acts the same as new( id => 'some_session_name'), i.e., it creates a session with that id.

=item $s->register();

kSession.pm  view on Meta::CPAN

    # unregistered "zmienna1"
    $s->unregister("zmienna1");
    $s->set("zmienna1","wartosc2");
    print $s->get("zmienna1"); #should print out -1
    
    $s->unset(); # unregister all variables
    $s->destroy(); # delete session with this ID

I<Marcin Krzyzanowski>

=item Sessions, URLs, and Cookies

 use strict;
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use CGI::kSession;
 use CGI::Cookie;

    my $cgi = new CGI;
    my $last_sid = $cgi->param("SID");
    my $c = new CGI::Cookie(-name=>'SID',-value=>$last_sid);
    my ($id, $key, $value);

    my $s = new CGI::kSession(path=>"/tmp/");

    print $cgi->header(-cookie=>$c);

    print $cgi->start_html();

    if ($last_sid) {
        # note: the following I used for mozilla - your mileage may vary
        my $cookie_sid = (split/[=;]/, (fetch CGI::Cookie)->{SID})[1];

        if ($cookie_sid) {
            print "<b>We are now reading from the cookie:</b><p>";
            $id = $s->id($cookie_sid);
            $s->start($cookie_sid);
            print "The cookie's id: $cookie_sid<br>";
            print "Here's the test_value: ".$s->get("test_key")."<br>";
        } else {
            print "<b>We are now reading from the URL parameters:</b><p>";
            $id = $s->id($last_sid);



( run in 2.109 seconds using v1.01-cache-2.11-cpan-e9199f4ba4c )