Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

session variables

by rjsaulakh (Beadle)
on May 28, 2005 at 10:48 UTC ( [id://461320]=perlquestion: print w/replies, xml ) Need Help??

rjsaulakh has asked for the wisdom of the Perl Monks concerning the following question:

i will try to explain what i want trying to accomplish
i am having a html loginpage through which the user tries to login and after that he can view database and also update it depending on the priveledges he has
i need to maintain session variables for username,password , login time , logout time , parts of database he has viweed and parts which he has edited
i should be able to have n number of session variables depending on my requirement
i have to write this code in CGI/perl
can some please help me how can i accomplish this task
please give me some guidelines so that i can work on the same

i have also tried to write a code where i can have session variables for login name , logout time , login time and others

#!c:\Perl\bin\perl.exe -w use strict; use CGI::Carp qw(fatalsToBrowser); #die "Bad error here"; use CGI; use CGI::Cookie; use Data::Dumper; use CGI::Session; my $cgi = new CGI; #Generating a new session my $session = new CGI::Session("driver:File", undef, { + #giving the directory where the session var +iables will be stored Directory=>"\\B2R6A056A\wwwroot\Amexpmo\lo +gin\amex\raman" } ) #incase of any error the session close giving an error or die $CGI::Session::errstr; print $cgi->header; print $cgi->start_html; #print <<HERE; #<b>jkasgdf</b> use constant SESSION_COOKIE => "MY_SITE_SIDE"; my $sid = $cgi->cookie("SESSION_COOKIE") || $cgi->param("sid") || unde +f; #creating a new session print "Your session id is ", $session->id(); # A cookie is being created which is then being send to the user brows +er my $cookie = $cgi->param(-name => SESSION_COOKIE, -value => $session->id, #sessiion expires after 3 hours -expires=>"+3h"); print $cgi->header(-cookie=>$cookie); $session->save_param($cgi, ["userid", "password"]); # this line saves all the available/accessible CGI params $session->save_param($cgi); #using data:;dumper to print the session variables getting stored print Dumper(\$session);

i am using IIS server for the same and working with windows

Replies are listed 'Best First'.
Re: session variables
by Jaap (Curate) on May 28, 2005 at 12:38 UTC
    Well... according to CGI::Session, you can just do this:
    ### $session already initialised as in your code # Set the username to Bart $session->param('username', 'Bart'); ... #retrieve and print the username print $session->('username'); #prints Bart
    Would that work for you?
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: session variables
by astroboy (Chaplain) on May 28, 2005 at 18:48 UTC
    it looks to me that be the time you do (Line 47)
    print $cgi->header(-cookie=>$cookie);
    it's too late, because you've already sent you header with (Line 26)
    print $cgi->header;
    Have a look at the tutorial and the cookbook

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://461320]
Approved by lamp
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-24 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found