Re: [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-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 > > |