RE: [Cgi-session-user] CGI::Session does not seem to be working for me
Brought to you by:
sherzodr
From: Sherzod R. <she...@ha...> - 2005-09-13 01:11:36
|
Vahid Try the following short script to test. If everything goes well, you = should see a persistent session id, and a counter which should increment each = time the page is revisited or refreshed (see http://author.handalak.com/cgi-bin/session ). If it doesn't, there = really is a problem and we'll work on it. P.S. You would discover this eventually, but you should look into CGI::Application and HTML::Template (Or Template Toolkit). The way = you're doing things right now (with if/else, and embedded 'HTML'), you can only = go so far. #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp ('fatalsToBrowser'); use CGI::Session; my $query =3D CGI->new(); my $session =3D CGI::Session->new(undef, undef, {Directory=3D>'/tmp'}); my $counter =3D $session->param('counter') || 0; $session->param('counter', ++$counter); my $cookie =3D $query->cookie(-name=3D>$session->name, = -value=3D>$session->id, -expires=3D>"+1h"); print $query->header(-cookie=3D>$cookie), $query->start_html("CGI::Session - " . $session->VERSION), $query->h1("Testing CGI::Session " . $session->VERSION), $query->h2($session->name . " : " . $session->id), $query->h3("Counter: $counter"), $query->end_html(); If it works, there's a problem with your code. > -----Original Message----- > From: cgi...@li...=20 > [mailto:cgi...@li...] On=20 > Behalf Of Vahid Hedayati > Sent: Monday, September 12, 2005 11:26 AM > To: cgi...@li... > Subject: [Cgi-session-user] CGI::Session does not seem to be=20 > working for me > Importance: High >=20 >=20 > CGI::Session version (3) / Perl v.5.8.6 : on FreeBSD 4.7 >=20 > I have been trying for many hours to get CGI::Session to work: >=20 > Here is my outcome after many hours of online searching testing: >=20 > Trying to run a cgi script which authenticates after step 1 and then=20 > runs specfic actions once authenticated.. >=20 > Here is the web results: >=20 >=20 > _____+++++++ > Original Session ID is > ++++ >=20 > Welcome vahid you are now logged in >=20 > Global username =3D vahid ::: 8d257f413fab17680ea94a176b3d71a6Clik me=20 > <http://logmgr/cgi-bin/Provision2.cgi?act=3Dvf> >=20 > __________________Once clicked shows no STORED Session ID =20 > and no global=20 > username at the bottom has a new SESSION ID: --> >=20 > ___+++++++ > Original Session ID is > ++++ > Global username =3D ::: 6afdaa81cb7c88dc195e1aaab41adf59Clik me=20 > <http://logmgr/cgi-bin/Provision2.cgi?act=3Dvf> >=20 >=20 > Basically what ever i have tried i end up with new session ids.. >=20 >=20 > here is the code: >=20 >=20 > This is the top of the script: >=20 >=20 >=20 > if ($act eq '' ) { > $cg =3D new CGI; > $session =3D new CGI::Session(undef,undef,{Directory=3D>"/tmp/"}); > $cookie =3D $cg->cookie(CGISESSID =3D> $session->id); > print $cg->header( -cookie=3D>$cookie ); > $sid=3D$session->id; > print "Session ID is $sid<br>"; > &startup(); > } else { > $cg =3D new CGI; > $sid=3D$cg->cookie("CGISESSID"); > print "_____$sid+++++++<br>"; > $session =3D new CGI::Session(undef,$sid,{Directory=3D>"/tmp/"}); > print "Original Session ID is $sid<br>"; > $sid =3D $session->id(); > print "++++$sid_____<br>"; > &$act; > } >=20 > sub startup { >=20 > $value=3D"logon2.htm"; > &do($value); > } >=20 >=20 >=20 > sub login { > $username=3D$cgi->param(username); > $pass=3D$cgi->param(pass); > if (($pass eq '') || ($username eq '' ) ) { > print "<hr size=3D3 width=3D100%>"; > print "Missing Fields please hit back and try again - =20 > process halted"; > print "<hr size=3D3 width=3D100%>"; > } else { > my $result =3D $ldap->bind("uid=3D$username,$base", = password=3D>$pass); > if($result->is_error()){ > my $errorMessage =3D $result->error(); > print "$errorMessage"; > } else { > $session->param( "user_name","$username" ); > print "<p class=3Dtd align=3Dcenter>Welcome $username you are now = > logged in</p>"; > &vf; > # print=20 > "<script>\nwindow.location.replace(\"/cgi-bin/$formname?act=3Dvf > \");\n</script>"; > } > } > } >=20 > sub vf { > #$gname=3D cookie($gusername); > $gname =3D $session->param("user_name"); >=20 > print "Global username =3D $gname ::: $sid"; > print "<a href=3D/cgi-bin/Provision2.cgi?act=3Dvf>Clik me</a>"; > } >=20 >=20 >=20 >=20 >=20 > ------------------------------------------------------- > SF.Net email is Sponsored by the Better Software Conference & EXPO > September 19-22, 2005 * San Francisco, CA * Development=20 > Lifecycle Practices > Agile & Plan-Driven Development * Managing Projects & Teams *=20 > Testing & QA > Security * Process Improvement & Measurement *=20 > http://www.sqe.com/bsce5sf > _______________________________________________ > Cgi-session-user mailing list > Cgi...@li... > https://lists.sourceforge.net/lists/listinfo/cgi-session-user >=20 >=20 |