[Cgi-session-user] CGI::Session->new not accepting sid
Brought to you by:
sherzodr
From: Niklas U. <ul...@gm...> - 2007-06-30 23:12:42
|
Look at this code: ******************************************************** #!/usr/bin/perl -w use strict; #use funcs; use DBI; use CGI ':standard'; use CGI::Session qw/-api3/; my $dbh = openDB(); my $sid = CGI->new->cookie("CGISESSID") or undef; my $session = CGI::Session->new("driver:postgresql;id:md5", $sid, {Handle=>$dbh, ColumnType=>"binary"}) or die CGI::Session->errstr; $session->expire('+2h'); my $CGISESSID = $session->id(); print $session->header(); makeHTML('test'); print $sid . "<BR>\n"; print $CGISESSID . "<BR>\n"; finnishUp(); sub openDB { #open db #$dbh = DBI->connect ( "dbi:Pg:dbname=frm", "frmdbusr", "256"); $dbh = DBI->connect("dbi:Pg:dbname=zerus;host=localhost;port=5432"$ "zuser", "1"); if ( !defined $dbh ) { die "Cannot connect to database!\n"; } $dbh; } sub makeHTML { print "<HTML><TITLE>${_[0]}</TITLE><BODY bgcolor='\#000000' text='$ } sub finnishUp { print end_html(); print $@, "<BR>\n"; # if(defined($DBI)){ print $DBI::errstr, "<BR>\n"; } eval { $dbh->disconnect; }; } ******************************************************** Or, if you're super lazy here's some psuedo: sid=cookie s=new session(sid) print sid print s.sid ******************************************************** The output should be two lines with the same value, but I get different, like this: bbeff82a55788c38789017b1fe75a333 276bc36e5a9d826564131b0f0bf37a43 And if I run it again I get: 276bc36e5a9d826564131b0f0bf37a43 ce580941292833cf55c70984632cba97 and the fast eyed can see that the second line of the first is the same as the first line of the second. Why does this happen? new must be wrong, but how? And more importantly how can i fix it? ;) I sometimes get it to work, and then it works fine, but if I clear the cookies of my browser it stops working and gives the above bug. Thanks for your time and happy programming (or scripting, since this is a scripting language) |