# Object initialization:
use CGI::Session;
my $session = new CGI::Session("driver:File", undef, {Directory=>'/tmp'});
# getting the effective session id:
my $CGISESSID = $session->id();
# storing data in the session
$session->param('f_name', 'Sherzod');
# or
$session->param(-name=>'l_name', -value=>'Ruzmetov');
# retrieving data
my $f_name = $session->param('f_name');
# or
my $l_name = $session->param(-name=>'l_name');
# clearing a certain session parameter
$session->clear(["_IS_LOGGED_IN"]);
# expire '_IS_LOGGED_IN' flag after 10 idle minutes:
$session->expire(_IS_LOGGED_IN => '+10m')
# expire the session itself after 1 idle hour
$session->expire('+1h');
# delete the session for good
$session->delete();
I donno man, my perl is ****ed to the sky. And all I ended up downloading from that session article above was “File.pm” WTF?! And my perl doesnt even have “Makefile.PL” and I dont see how THAT would install modules, when the command is just like
Makefile.pl
nmake
nmake test
???How the **** would that install a module?!!! ARG
Extract the contents to your Perl CGI library location, which considering you’re using Activeperl by the looks of it, should be something like C:\Perl\lib\CGI
You should now have a folder that includes the following files:
Now, once I create a session, how do I get data from it, without creating a new session?! Like, to get at the data from a different page, without re-generating a session id
read the man pages, man. Then come back with any questions that couldn’t be answered. If they are too difficult or arduous for you, then so is programming.
I have installed the Perl Module Session …but I am still not sure that how could I retrieve session parameters from page other than other page which has stored the session varibales …
Thanx for quick reply …I saw your code but I guess you are reading the session parametrs on the same page … I wanna read the parameters value on the different page , I am a new bie so I could be the wrong but I didnt succeed reading parameters value on 2nd page using your code , can you please please provide me code for the second page …by 2nd page I mean any page in the application that tries to access session parameters other than the page that has actually stored value…
use strict;
use CGI::Session;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
#create a new CGI object.
my $cgi = new CGI;
$CGI::DISABLE_UPLOADS = 1; # Disable uploads
$CGI::POST_MAX = 512 * 1024; # limit posts to 512K max
#create my session
my $session = new CGI::Session(undef, $sid, {Directory=>‘c:/temp/session/’});
#set a cookie to remember the session id #and create the cookie with an 1hour limit
my $cookie = $cgi->cookie(-name=>“CGISESSID”,
-value=>$sid,
-expires=>“+1h”,
-path=>“/”);
#set the cookie…
print $cgi->header(-cookie => $cookie );
#set the session to expire in 1 hour
$session->expire(“+1h”);
#store some parameters
$session->param(“today”, “Monday”);
$session->flush(); #flush it out to disk…
On another page… you would pretty much the same thing… . except, instead of setting the cookie… you want to retrieve the cookie… The cookie will contain the session id which you use to ‘reconnect’ to the session and get at its paramets…
use strict;
use CGI::Session;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
#create a new CGI object.
my $cgi = new CGI;
$CGI::DISABLE_UPLOADS = 1; # Disable uploads
$CGI::POST_MAX = 512 * 1024; # limit posts to 512K max
#get my cookie… or set it to undef
$sid = $cgi->cookie(“CGISESSID”) || undef;
#if the cookie contains a valid session id, use the old one… #if its undef’d create a new session…
my $session = new CGI::Session(undef, $sid, {Directory=>‘c:/temp/session/’});
#get at a session parameters
print $session->param(“today”);
using cookies is one way of tracking the session id… you can append the session id to the query string if you want to.
Thanx for your replies and helping me … Now I am feeling myself dumb *** … I still cant retieve values on 2nd page … I feel like crying … It does not print any thing on 2nd page and 2nd page generate new session id always … Please please help me … I have lost … please see my commenst with your code …please please
Thanx in advance
Regards
Noman
Code on PAge 1
#use strict; *** I HAVE TO COMMENT IT OW IT ASK $sid
TO INITIALIZE ***
use CGI::Session;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $cgi = new CGI;
$CGI::DISABLE_UPLOADS = 1; # Disable uploads
$CGI::POST_MAX = 512 * 1024; # limit posts to 512K max
my $session = new CGI::Session(undef, $sid , {Directory=>‘c:/temp/session/’});
******** WAHTS is $sid in above line *******
my $cookie = $cgi->cookie(-name=>“CGISESSID”, -value=>$sid, -expires=>“+1h”, -path=>“/”);
print $cgi->header(-cookie => $cookie );
$session->expire(“+1h”);
$session->param(“today”, “Monday”);
$session->flush(); #flush it out to disk…
Page 2 Code
use CGI::Session;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $cgi = new CGI;
$CGI::DISABLE_UPLOADS = 1; # Disable uploads
$CGI::POST_MAX = 512 * 1024; # limit posts to 512K max
$sid = $cgi->cookie(“CGISESSID”) || undef; # WHAT is CGISESSID
my $session = new CGI::Session(undef, $sid, {Directory=>‘c:/temp/session/’});
It always creates new session using above lines tahtshwy i guess ### it cant read any thing , what is $sid …
print $session->param(“today”); ## does not print any thing
I have been experiminting with with following code and come to the following conclusion that in code for page 1 you created a cookie named CGISESSID and its value is session id and on page 2 , u got session created on page 1 via CGISESSID named cookie’s value …but problem is that code on page 2 cant find the cookie name CGISESSID thatswhy it always create new session …How do I know that …it creates one file in temp dir after running code 1 and another after running code of page 2 … if I can come to know why code on page 2 cant find cookie named CGISESSID …my problem would be solved … Help please Gurus
I am new bie to perl so please excuse me if all above is rubbish …
Regards
Noman
Code for Page 1
use CGI::Session;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$cgi = new CGI;
$session = new CGI::Session(undef, undef , {Directory=>‘c:/temp/session/’});
$cookie = $cgi->cookie(CGISESSID => $session->id );
print $cgi->header(-cookie => $cookie );
$session->param(“today”, “Monday”);
$session->flush(); #flush it out to disk…
Code for Page 2
use CGI::Session;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$cgi = new CGI;
$sid = $cgi->cookie(“CGISESSID”) || undef;
my $session = new CGI::Session(undef, $sid, {Directory=>‘c:/temp/session/’});