Thread: [Cgi-session-user] CGI::Session does not seem to be working for me
Brought to you by:
sherzodr
From: Vahid H. <vah...@bu...> - 2005-09-12 15:26:14
|
CGI::Session version (3) / Perl v.5.8.6 : on FreeBSD 4.7 I have been trying for many hours to get CGI::Session to work: Here is my outcome after many hours of online searching testing: Trying to run a cgi script which authenticates after step 1 and then runs specfic actions once authenticated.. Here is the web results: _____+++++++ Original Session ID is ++++ Welcome vahid you are now logged in Global username = vahid ::: 8d257f413fab17680ea94a176b3d71a6Clik me <http://logmgr/cgi-bin/Provision2.cgi?act=vf> __________________Once clicked shows no STORED Session ID and no global username at the bottom has a new SESSION ID: --> ___+++++++ Original Session ID is ++++ Global username = ::: 6afdaa81cb7c88dc195e1aaab41adf59Clik me <http://logmgr/cgi-bin/Provision2.cgi?act=vf> Basically what ever i have tried i end up with new session ids.. here is the code: This is the top of the script: if ($act eq '' ) { $cg = new CGI; $session = new CGI::Session(undef,undef,{Directory=>"/tmp/"}); $cookie = $cg->cookie(CGISESSID => $session->id); print $cg->header( -cookie=>$cookie ); $sid=$session->id; print "Session ID is $sid<br>"; &startup(); } else { $cg = new CGI; $sid=$cg->cookie("CGISESSID"); print "_____$sid+++++++<br>"; $session = new CGI::Session(undef,$sid,{Directory=>"/tmp/"}); print "Original Session ID is $sid<br>"; $sid = $session->id(); print "++++$sid_____<br>"; &$act; } sub startup { $value="logon2.htm"; &do($value); } sub login { $username=$cgi->param(username); $pass=$cgi->param(pass); if (($pass eq '') || ($username eq '' ) ) { print "<hr size=3 width=100%>"; print "Missing Fields please hit back and try again - process halted"; print "<hr size=3 width=100%>"; } else { my $result = $ldap->bind("uid=$username,$base", password=>$pass); if($result->is_error()){ my $errorMessage = $result->error(); print "$errorMessage"; } else { $session->param( "user_name","$username" ); print "<p class=td align=center>Welcome $username you are now logged in</p>"; &vf; # print "<script>\nwindow.location.replace(\"/cgi-bin/$formname?act=vf\");\n</script>"; } } } sub vf { #$gname= cookie($gusername); $gname = $session->param("user_name"); print "Global username = $gname ::: $sid"; print "<a href=/cgi-bin/Provision2.cgi?act=vf>Clik me</a>"; } |
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 |
From: Cees H. <ce...@gm...> - 2005-09-13 03:19:19
|
On 9/12/05, Sherzod Ruzmetov <she...@ha...> wrote: > Vahid > 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. I thought I'd take the opportunity to show how easy this can actually be done, and how CGI::Application can really simplify your web apps.=20 And also if I may, I'll take a second to show off the new Authentication plugin for CGI::Application (which can use CGI::Session to keep things on topic). The new Authentication plugin will be on CPAN by the end of the week, but a preview version is available here:=20 http://cees.crtconsulting.ca/perl/modules/CGI-Application-Plugin-Authentica= tion-0.01.tar.gz Also, I should note that there is no LDAP driver yet, but it is very easy to build new authentication drivers (and LDAP is a planned addition). For simplicity, just put all the following files into a web enabled directory and call myapp.cgi from a web browser: -------------------------------------- myapp.cgi -------------------------------------- #!/usr/bin/perl use strict; use warnings; use lib qw/./; use MyApp; MyApp->new->run; -------------------------------------- MyApp.pm -------------------------------------- package MyApp; use base qw/CGI::Application/; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Authentication; MyApp->auth->config( #DRIVER =3D> [ 'LDAP', DSN =3D> $dsn, PASSWORD =3D> $password ], DRIVER =3D> [ 'Generic', { user1 =3D> '123', user2 =3D> '1234' } ], STORE =3D> 'Session', LOGOUT_RUNMODE =3D> 'start', ); sub setup { my $self =3D shift; $self->tmpl_path('./'); $self->auth->protected_runmodes('protected'); } sub start : StartRunmode { my $self =3D shift; my $session =3D $self->session; my $template =3D $self->load_tmpl('start.tmpl'); $template->param( id =3D> $session->id, new_session =3D> $session->is_new ); return $template->output; } sub protected : Runmode { my $self =3D shift; my $session =3D $self->session; my $auth =3D $self->auth; my $template =3D $self->load_tmpl('protected.tmpl'); $template->param( id =3D> $session->id, username =3D> $auth->username, ); return $template->output; } 1; -------------------------------------- start.tmpl -------------------------------------- <html> <body> <h2>Start page</h2> <p>Session ID: <TMPL_VAR id></p> <p>New Session: <TMPL_IF new_session>Yes<TMPL_ELSE>No</TMPL_IF></p> <p><a href=3D"?rm=3Dprotected">View Protected Page</a></p> </body> </html> -------------------------------------- protected.tmpl -------------------------------------- <html> <body> <h2>Protected page</h2> <p>Session ID: <TMPL_VAR id></p> <p>Username: <TMPL_VAR username></p> <p><a href=3D"?rm=3Dstart">View Start Page</a></p> <p><a href=3D"?auth_logout=3D1">Logout</a></p> </body> </html> There are lots of other things you can do to simplify things (for example using template page headers), and also I would personally use Template Toolkit, but this should be a good showcase of some of the things that can be done with CGI::Application. Cheers, Cees |
From: Vahid H. <vah...@bu...> - 2005-09-14 13:56:54
|
The below test fails it keeps resetting session ID's and counter remains on 1.. Testing CGI::Session 3.1.4.1 CGISESSID : dbaaf2e4bb0fdc16982906e6c8ff880c Counter: 1 Testing CGI::Session 3.1.4.1 CGISESSID : a1b974c2eef270e24dd42ed4a8803f18 Counter: 1 I also saw another posting so i thought i try out the script the below script fails on section 2 ok 1 - found session id not ok 2 - found session data file # Failed test (./test.pl at line 16) 1..2 # Looks like you failed 1 test of 2. #!/usr/bin/perl -w use File::Spec; use Test::More qw/no_plan/; use CGI::Session; if (CGI::Session->VERSION >= 4) { *CGI::Session::DESTROY = sub { my $s = shift; $s->flush() or die "Flush seems to have failed: ".$s->errstr; }; } my $dir = File::Spec->catdir('t', 'sessiondata'); my $id; my $ses = CGI::Session->new(undef,undef,{Directory=> $dir }); $id = $ses->id(); ok($id, "found session id"); END { ok(-r "$dir/cgisess_".$id, "found session data file"); } Sherzod Ruzmetov wrote: >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 = CGI->new(); >my $session = CGI::Session->new(undef, undef, {Directory=>'/tmp'}); >my $counter = $session->param('counter') || 0; >$session->param('counter', ++$counter); > >my $cookie = $query->cookie(-name=>$session->name, -value=>$session->id, >-expires=>"+1h"); >print $query->header(-cookie=>$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... >>[mailto:cgi...@li...] On >>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 >>working for me >>Importance: High >> >> >>CGI::Session version (3) / Perl v.5.8.6 : on FreeBSD 4.7 >> >>I have been trying for many hours to get CGI::Session to work: >> >>Here is my outcome after many hours of online searching testing: >> >>Trying to run a cgi script which authenticates after step 1 and then >>runs specfic actions once authenticated.. >> >>Here is the web results: >> >> >>_____+++++++ >>Original Session ID is >>++++ >> >>Welcome vahid you are now logged in >> >>Global username = vahid ::: 8d257f413fab17680ea94a176b3d71a6Clik me >><http://logmgr/cgi-bin/Provision2.cgi?act=vf> >> >>__________________Once clicked shows no STORED Session ID >>and no global >>username at the bottom has a new SESSION ID: --> >> >>___+++++++ >>Original Session ID is >>++++ >>Global username = ::: 6afdaa81cb7c88dc195e1aaab41adf59Clik me >><http://logmgr/cgi-bin/Provision2.cgi?act=vf> >> >> >>Basically what ever i have tried i end up with new session ids.. >> >> >>here is the code: >> >> >>This is the top of the script: >> >> >> >>if ($act eq '' ) { >> $cg = new CGI; >> $session = new CGI::Session(undef,undef,{Directory=>"/tmp/"}); >> $cookie = $cg->cookie(CGISESSID => $session->id); >> print $cg->header( -cookie=>$cookie ); >> $sid=$session->id; >> print "Session ID is $sid<br>"; >> &startup(); >>} else { >> $cg = new CGI; >> $sid=$cg->cookie("CGISESSID"); >> print "_____$sid+++++++<br>"; >> $session = new CGI::Session(undef,$sid,{Directory=>"/tmp/"}); >> print "Original Session ID is $sid<br>"; >> $sid = $session->id(); >> print "++++$sid_____<br>"; >> &$act; >>} >> >>sub startup { >> >> $value="logon2.htm"; >> &do($value); >>} >> >> >> >>sub login { >> $username=$cgi->param(username); >> $pass=$cgi->param(pass); >> if (($pass eq '') || ($username eq '' ) ) { >> print "<hr size=3 width=100%>"; >> print "Missing Fields please hit back and try again - >>process halted"; >> print "<hr size=3 width=100%>"; >> } else { >> my $result = $ldap->bind("uid=$username,$base", password=>$pass); >> if($result->is_error()){ >> my $errorMessage = $result->error(); >> print "$errorMessage"; >> } else { >> $session->param( "user_name","$username" ); >> print "<p class=td align=center>Welcome $username you are now >>logged in</p>"; >> &vf; >> # print >>"<script>\nwindow.location.replace(\"/cgi-bin/$formname?act=vf >>\");\n</script>"; >> } >> } >>} >> >>sub vf { >> #$gname= cookie($gusername); >> $gname = $session->param("user_name"); >> >> print "Global username = $gname ::: $sid"; >> print "<a href=/cgi-bin/Provision2.cgi?act=vf>Clik me</a>"; >>} >> >> >> >> >> >>------------------------------------------------------- >>SF.Net email is Sponsored by the Better Software Conference & EXPO >>September 19-22, 2005 * San Francisco, CA * Development >>Lifecycle Practices >>Agile & Plan-Driven Development * Managing Projects & Teams * >>Testing & QA >>Security * Process Improvement & Measurement * >>http://www.sqe.com/bsce5sf >>_______________________________________________ >>Cgi-session-user mailing list >>Cgi...@li... >>https://lists.sourceforge.net/lists/listinfo/cgi-session-user >> >> >> >> > > > |
From: Sherzod R. <she...@ha...> - 2005-09-14 19:32:32
|
Vahid, You seriously have to upgrade. The one you're using right now is 4 years, and at least 20 releases old. Get the most recent from http://search.cpan.org/dist/CGI-Session/ . Re-try those two scripts, and let us know. -- Sherzod > -----Original Message----- > From: cgi...@li... > [mailto:cgi...@li...] On > Behalf Of Vahid Hedayati > Sent: Wednesday, September 14, 2005 9:57 AM > To: cgi...@li... > Subject: Re: [Cgi-session-user] CGI::Session does not seem to > be working for me > Importance: High > > > The below test fails it keeps resetting session ID's and counter > remains on 1.. > > > Testing CGI::Session 3.1.4.1 > > > CGISESSID : dbaaf2e4bb0fdc16982906e6c8ff880c > > > Counter: 1 > > > Testing CGI::Session 3.1.4.1 > > > CGISESSID : a1b974c2eef270e24dd42ed4a8803f18 > > > Counter: 1 > > > I also saw another posting so i thought i try out the script > the below > script fails on section 2 > > ok 1 - found session id > not ok 2 - found session data file > # Failed test (./test.pl at line 16) > 1..2 > # Looks like you failed 1 test of 2. > > #!/usr/bin/perl -w > use File::Spec; > use Test::More qw/no_plan/; > > use CGI::Session; > > if (CGI::Session->VERSION >= 4) { > *CGI::Session::DESTROY = sub { > my $s = shift; > $s->flush() or die > "Flush seems to > have failed: ".$s->errstr; > }; > } > > my $dir = File::Spec->catdir('t', 'sessiondata'); > my $id; > my $ses = CGI::Session->new(undef,undef,{Directory=> $dir }); > $id = $ses->id(); > ok($id, "found session id"); > END { ok(-r "$dir/cgisess_".$id, "found session data file"); } > > > > > > > Sherzod Ruzmetov wrote: > > >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 = CGI->new(); > >my $session = CGI::Session->new(undef, undef, {Directory=>'/tmp'}); > >my $counter = $session->param('counter') || 0; > >$session->param('counter', ++$counter); > > > >my $cookie = $query->cookie(-name=>$session->name, > -value=>$session->id, > >-expires=>"+1h"); > >print $query->header(-cookie=>$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... > >>[mailto:cgi...@li...] On > >>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 > >>working for me > >>Importance: High > >> > >> > >>CGI::Session version (3) / Perl v.5.8.6 : on FreeBSD 4.7 > >> > >>I have been trying for many hours to get CGI::Session to work: > >> > >>Here is my outcome after many hours of online searching testing: > >> > >>Trying to run a cgi script which authenticates after step 1 > and then > >>runs specfic actions once authenticated.. > >> > >>Here is the web results: > >> > >> > >>_____+++++++ > >>Original Session ID is > >>++++ > >> > >>Welcome vahid you are now logged in > >> > >>Global username = vahid ::: 8d257f413fab17680ea94a176b3d71a6Clik me > >><http://logmgr/cgi-bin/Provision2.cgi?act=vf> > >> > >>__________________Once clicked shows no STORED Session ID > >>and no global > >>username at the bottom has a new SESSION ID: --> > >> > >>___+++++++ > >>Original Session ID is > >>++++ > >>Global username = ::: 6afdaa81cb7c88dc195e1aaab41adf59Clik me > >><http://logmgr/cgi-bin/Provision2.cgi?act=vf> > >> > >> > >>Basically what ever i have tried i end up with new session ids.. > >> > >> > >>here is the code: > >> > >> > >>This is the top of the script: > >> > >> > >> > >>if ($act eq '' ) { > >> $cg = new CGI; > >> $session = new CGI::Session(undef,undef,{Directory=>"/tmp/"}); > >> $cookie = $cg->cookie(CGISESSID => $session->id); > >> print $cg->header( -cookie=>$cookie ); > >> $sid=$session->id; > >> print "Session ID is $sid<br>"; > >> &startup(); > >>} else { > >> $cg = new CGI; > >> $sid=$cg->cookie("CGISESSID"); > >> print "_____$sid+++++++<br>"; > >> $session = new CGI::Session(undef,$sid,{Directory=>"/tmp/"}); > >> print "Original Session ID is $sid<br>"; > >> $sid = $session->id(); > >> print "++++$sid_____<br>"; > >> &$act; > >>} > >> > >>sub startup { > >> > >> $value="logon2.htm"; > >> &do($value); > >>} > >> > >> > >> > >>sub login { > >> $username=$cgi->param(username); > >> $pass=$cgi->param(pass); > >> if (($pass eq '') || ($username eq '' ) ) { > >> print "<hr size=3 width=100%>"; > >> print "Missing Fields please hit back and try again - > >>process halted"; > >> print "<hr size=3 width=100%>"; > >> } else { > >> my $result = $ldap->bind("uid=$username,$base", password=>$pass); > >> if($result->is_error()){ > >> my $errorMessage = $result->error(); > >> print "$errorMessage"; > >> } else { > >> $session->param( "user_name","$username" ); > >> print "<p class=td align=center>Welcome $username you are now > >>logged in</p>"; > >> &vf; > >> # print > >>"<script>\nwindow.location.replace(\"/cgi-bin/$formname?act=vf > >>\");\n</script>"; > >> } > >> } > >>} > >> > >>sub vf { > >> #$gname= cookie($gusername); > >> $gname = $session->param("user_name"); > >> > >> print "Global username = $gname ::: $sid"; > >> print "<a href=/cgi-bin/Provision2.cgi?act=vf>Clik me</a>"; > >>} > >> > >> > >> > >> > >> > >>------------------------------------------------------- > >>SF.Net email is Sponsored by the Better Software Conference & EXPO > >>September 19-22, 2005 * San Francisco, CA * Development > >>Lifecycle Practices > >>Agile & Plan-Driven Development * Managing Projects & Teams * > >>Testing & QA > >>Security * Process Improvement & Measurement * > >>http://www.sqe.com/bsce5sf > >>_______________________________________________ > >>Cgi-session-user mailing list > >>Cgi...@li... > >>https://lists.sourceforge.net/lists/listinfo/cgi-session-user > >> > >> > >> > >> > > > > > > > > > > ------------------------------------------------------- > SF.Net email is sponsored by: > Tame your development challenges with Apache's Geronimo App > Server. Download > it for free - -and be entered to win a 42" plasma tv or your very own > Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php > _______________________________________________ > Cgi-session-user mailing list > Cgi...@li... > https://lists.sourceforge.net/lists/listinfo/cgi-session-user > > |
From: Vahid H. <vah...@bu...> - 2005-09-15 14:23:57
|
Hi Sherzod Thanks for your help on this, I have upgraded the CGI::Session to latest version and it seems to be working but I am still having issues with it Test results from your scripts html : Testing CGI::Session 4.02 CGISESSID : a893c42c62d59c4a8c08a53be003a5cc Counter: 1Testing CGI::Session 4.02 CGISESSID : a893c42c62d59c4a8c08a53be003a5cc Counter: 2 Test script now works fine it keeps the counter going up with same session ID, the file test failed on 2: not ok 2 - found session data file # Failed test (/home/vahid/test.pl at line 11) 1..2 # Looks like you failed 1 test of 2. !/usr/bin/perl use File::Spec; use Test::More qw/no_plan/; use strict; use CGI::Session; my $dir = File::Spec->catdir('t', '/tmp/'); my $id; my $ses = CGI::Session->new(undef,undef,{Directory=> $dir }); $id = $ses->id(); ok($id, "found session id"); ok(-r "$dir/cgisess_".$id, "found session data file"); <--line 11 It now seems to be keeping same session ID but fails to bring back any values from it.. the user i log in with seems to remain as the correct user as it first logs in but when a link is clicked on which refreshes the script, it keeps same session ID but username value is not set.. The only time it has brought back correct value is after logging in whcih calls &view directly which then loads in the menu system.. the menu system kept returning guest too upon loggin in until i asked it to look up gname from $session->param values, but either way still no good since once a link is clicked on the username becomes guest... :( top of script.. &init_session; $gname=$session->param("un"); print "---$gname---"; if ($act eq '' ) { &startup(); } else { &$act; } the first procedure it hits after user logs in the bit that loads in view has the correct username .. sub login { $username=$cgi->param('username'); $pass=$cgi->param('pass'); if (($pass eq '') || ($username eq '' ) ) { print "<hr size=3 width=100%>"; print "Missing Fields please hit back and try again - process halted"; print "<hr size=3 width=100%>"; } else { my $result = $ldap->bind("uid=$username,$base", password=>$pass); if($result->is_error()){ my $errorMessage = $result->error(); print "<p class=td align=center><font size=5>$errorMessage<br>"; print "hit back and try again - process halted</p>"; } else { $session->param("un", $username); $gname=$session->param("un"); print "<p class=td align=center>Welcome $username you are now logged in</p>"; &view(); } } } sub init_session { $sid = $cgi->cookie('CGISESSID') || $cgi->param('CGISESSID') || undef; $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'}); $sid=$session->id; $gname=$session->param("un"); } sub menu { $gname=$session->param("un"); if ($gname eq '') { $gname="Guest"; } rint <<"EOF"; <a href=/cgi-bin/$formname?act=logout>LOGOUT</a> | | <a href=/cgi-bin/$formname?act=logbook>LOGBOOK</a> | </td></tr><tr><td class=td bgcolor=#FF0000 align=right> SESSION ID: $sid | USERNAME: $gname | IP ADDRESS: $ipaddress </table> EOF } } } sub view { my $dle=$cgi->param('dle'); my $type=$cgi->param('type'); if ($type eq '') { if ( ($dle eq '')) { &dbi_search(); } else { &dbi_search($dle); } } else { &dbi_search("$type"); } } sub dbi_search { &menu(); ..... } Thanks Vahid Sherzod Ruzmetov wrote: >Vahid, > >You seriously have to upgrade. The one you're using right now is 4 years, >and at least 20 releases old. Get the most recent from >http://search.cpan.org/dist/CGI-Session/ . > >Re-try those two scripts, and let us know. > >-- >Sherzod > > > > > > >>-----Original Message----- >>From: cgi...@li... >>[mailto:cgi...@li...] On >>Behalf Of Vahid Hedayati >>Sent: Wednesday, September 14, 2005 9:57 AM >>To: cgi...@li... >>Subject: Re: [Cgi-session-user] CGI::Session does not seem to >>be working for me >>Importance: High >> >> >>The below test fails it keeps resetting session ID's and counter >>remains on 1.. >> >> >> Testing CGI::Session 3.1.4.1 >> >> >> CGISESSID : dbaaf2e4bb0fdc16982906e6c8ff880c >> >> >> Counter: 1 >> >> >> Testing CGI::Session 3.1.4.1 >> >> >> CGISESSID : a1b974c2eef270e24dd42ed4a8803f18 >> >> >> Counter: 1 >> >> >>I also saw another posting so i thought i try out the script >>the below >>script fails on section 2 >> >>ok 1 - found session id >>not ok 2 - found session data file >># Failed test (./test.pl at line 16) >>1..2 >># Looks like you failed 1 test of 2. >> >>#!/usr/bin/perl -w >> use File::Spec; >> use Test::More qw/no_plan/; >> >> use CGI::Session; >> >> if (CGI::Session->VERSION >= 4) { >> *CGI::Session::DESTROY = sub { >> my $s = shift; >> $s->flush() or die >>"Flush seems to >> have failed: ".$s->errstr; >> }; >> } >> >> my $dir = File::Spec->catdir('t', 'sessiondata'); >> my $id; >> my $ses = CGI::Session->new(undef,undef,{Directory=> $dir }); >> $id = $ses->id(); >> ok($id, "found session id"); >> END { ok(-r "$dir/cgisess_".$id, "found session data file"); } >> >> >> >> >> >> >>Sherzod Ruzmetov wrote: >> >> >> >>>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 = CGI->new(); >>>my $session = CGI::Session->new(undef, undef, {Directory=>'/tmp'}); >>>my $counter = $session->param('counter') || 0; >>>$session->param('counter', ++$counter); >>> >>>my $cookie = $query->cookie(-name=>$session->name, >>> >>> >>-value=>$session->id, >> >> >>>-expires=>"+1h"); >>>print $query->header(-cookie=>$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... >>>>[mailto:cgi...@li...] On >>>>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 >>>>working for me >>>>Importance: High >>>> >>>> >>>>CGI::Session version (3) / Perl v.5.8.6 : on FreeBSD 4.7 >>>> >>>>I have been trying for many hours to get CGI::Session to work: >>>> >>>>Here is my outcome after many hours of online searching testing: >>>> >>>>Trying to run a cgi script which authenticates after step 1 >>>> >>>> >>and then >> >> >>>>runs specfic actions once authenticated.. >>>> >>>>Here is the web results: >>>> >>>> >>>>_____+++++++ >>>>Original Session ID is >>>>++++ >>>> >>>>Welcome vahid you are now logged in >>>> >>>>Global username = vahid ::: 8d257f413fab17680ea94a176b3d71a6Clik me >>>><http://logmgr/cgi-bin/Provision2.cgi?act=vf> >>>> >>>>__________________Once clicked shows no STORED Session ID >>>>and no global >>>>username at the bottom has a new SESSION ID: --> >>>> >>>>___+++++++ >>>>Original Session ID is >>>>++++ >>>>Global username = ::: 6afdaa81cb7c88dc195e1aaab41adf59Clik me >>>><http://logmgr/cgi-bin/Provision2.cgi?act=vf> >>>> >>>> >>>>Basically what ever i have tried i end up with new session ids.. >>>> >>>> >>>>here is the code: >>>> >>>> >>>>This is the top of the script: >>>> >>>> >>>> >>>>if ($act eq '' ) { >>>> $cg = new CGI; >>>> $session = new CGI::Session(undef,undef,{Directory=>"/tmp/"}); >>>> $cookie = $cg->cookie(CGISESSID => $session->id); >>>> print $cg->header( -cookie=>$cookie ); >>>> $sid=$session->id; >>>> print "Session ID is $sid<br>"; >>>> &startup(); >>>>} else { >>>> $cg = new CGI; >>>> $sid=$cg->cookie("CGISESSID"); >>>> print "_____$sid+++++++<br>"; >>>> $session = new CGI::Session(undef,$sid,{Directory=>"/tmp/"}); >>>> print "Original Session ID is $sid<br>"; >>>> $sid = $session->id(); >>>> print "++++$sid_____<br>"; >>>> &$act; >>>>} >>>> >>>>sub startup { >>>> >>>>$value="logon2.htm"; >>>>&do($value); >>>>} >>>> >>>> >>>> >>>>sub login { >>>>$username=$cgi->param(username); >>>>$pass=$cgi->param(pass); >>>>if (($pass eq '') || ($username eq '' ) ) { >>>> print "<hr size=3 width=100%>"; >>>> print "Missing Fields please hit back and try again - >>>>process halted"; >>>> print "<hr size=3 width=100%>"; >>>>} else { >>>> my $result = $ldap->bind("uid=$username,$base", password=>$pass); >>>> if($result->is_error()){ >>>> my $errorMessage = $result->error(); >>>> print "$errorMessage"; >>>> } else { >>>> $session->param( "user_name","$username" ); >>>> print "<p class=td align=center>Welcome $username you are now >>>>logged in</p>"; >>>> &vf; >>>> # print >>>>"<script>\nwindow.location.replace(\"/cgi-bin/$formname?act=vf >>>>\");\n</script>"; >>>> } >>>>} >>>>} >>>> >>>>sub vf { >>>> #$gname= cookie($gusername); >>>> $gname = $session->param("user_name"); >>>> >>>> print "Global username = $gname ::: $sid"; >>>> print "<a href=/cgi-bin/Provision2.cgi?act=vf>Clik me</a>"; >>>>} >>>> >>>> >>>> >>>> >>>> >>>>------------------------------------------------------- >>>>SF.Net email is Sponsored by the Better Software Conference & EXPO >>>>September 19-22, 2005 * San Francisco, CA * Development >>>>Lifecycle Practices >>>>Agile & Plan-Driven Development * Managing Projects & Teams * >>>>Testing & QA >>>>Security * Process Improvement & Measurement * >>>>http://www.sqe.com/bsce5sf >>>>_______________________________________________ >>>>Cgi-session-user mailing list >>>>Cgi...@li... >>>>https://lists.sourceforge.net/lists/listinfo/cgi-session-user >>>> >>>> >>>> >>>> >>>> >>>> >>> >>> >>> >>> >> >>------------------------------------------------------- >>SF.Net email is sponsored by: >>Tame your development challenges with Apache's Geronimo App >>Server. Download >>it for free - -and be entered to win a 42" plasma tv or your very own >>Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php >>_______________________________________________ >>Cgi-session-user mailing list >>Cgi...@li... >>https://lists.sourceforge.net/lists/listinfo/cgi-session-user >> >> >> >> > > > >------------------------------------------------------- >SF.Net email is sponsored by: >Tame your development challenges with Apache's Geronimo App Server. Download >it for free - -and be entered to win a 42" plasma tv or your very own >Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php >_______________________________________________ >Cgi-session-user mailing list >Cgi...@li... >https://lists.sourceforge.net/lists/listinfo/cgi-session-user > > |