in reply to Re: Apache::Session::MySQL Help... Please
in thread Apache::Session::MySQL Help... Please

Yes, that database is connecting, and the cookie is being left. All the cookie holds is the session_id, I have MySQL hold everything else.

I have the same problem, even when I disable cookies and the sites just passes the session_id from page to page.

I have tracked it down to the following problems....

[Sat Dec 28 10:02:21 2002] index.cgi: (in cleanup) Can't call method " +release_all_locks" on an undefined value at /usr/lib/perl5/site_perl/ +5.6.1/Apache/Session.pm line 599 during global destruction. and index.cgi: (in cleanup) Can't call method "update" on an undefined val +ue at /usr/lib/perl5/site_perl/5.6.1/Apache/Session.pm line 508 durin +g global destruction. The code in my index.cgi file is pretty simple: #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard :cgi-lib escapeHTML); use Mail::Sendmail; #@ USE_STATEMENTS use Digest::MD5; use Crypt::CBC; use Crypt::Blowfish; use LWP::UserAgent; push(@inc, "/home/mydom/my_mods"); use FRHWebDB::Session; # This contains the MySQL connections #@ USE_STATEMENTS ReadParse(\%in); use vars qw($cookie $sess_id $sess_ref $page $logged_in %in);# These a +re global $sess_id = cookie ("session_id"); if ($sess_id eq "" && $in{sess_id} ne "") { $sess_id = $in{sess_id};#if no cookies then it's in the url } $sess_ref = FRHWebDB::Session->open_with_expiration(undef, $sess_id) i +f defined ($sess_id);#Open with Expriration require "/home/mydom/site/data.conf";#This contains header # information and other stuff, like menu and things like # that if ($in{pg} eq "quit" && defined($sess_ref)) { if ($sess_ref->attr ("remember_me") == 1) { $sess_ref->attr ("loggedin", 0); $message = qq~You have been Logged Out$nname_ws!<br><br>~;#$nn +ame_ws is their nickname with a # space in front of it, if no nick na +me then it's blank # (Out!) } else { Delete_Session_Forever($sess_ref); } } if (!defined ($sess_ref))# no session yet, so create one. { defined ($sess_ref = FRHWebDB::Session->open (undef, undef)) or error ("Could not create new session: $FRHWebDB::Session::e +rrstr"); $cookie = cookie (-name => "session_id", -value => $sess_ref->session_id(), -path => url (-absolute => 1), -expires => "+1y" );#Create the cookie to put on user pc at top_header() } get_cookie_values($sess_ref) if defined ($sess_id);#Ok, get # session values from the $sess_ref [apache::session]. get_company_values() if !defined($sess_id);#No session so # just define the company variables($co_name and such) require "/home/mydom/site/config.data";#Ok this one has all # the javascripts, css and lots of configuration variables, # and such. Plus a browser check. #Set expiration of session if none exists. $sess_ref->expires ($sess_ref->now() + (60*60*24*365)) if !defined ($s +ess_ref->expires()); $Page_Dir = "/home/mydom/site/pages";#directory where all # the pages in .conf files are stored. $pg = $in{pg}; $test_cookie2 = cookie ("session_id"); if (!defined ($test_cookie2)) {#users pc has cookies # Turned off, so add the session to every link and form # using the variables I've defined here. $nocookies = 1; $inc_sess_id = "&sess_id=" . $sess_ref->session_id(); $hidden_inc_sess_id = hidden(-name=>"sess_id", -value=>$sess_r +ef->session_id()); } else {#Ok, they do have cookies turned on! $nocookies = 0; $inc_sess_id = ""; $hidden_inc_sess_id = ""; } if (!$pg || !-e "$Page_Dir/$pg.conf") {#No page so load home require "$Page_Dir/home.conf"; $page .= $page_content; } elsif(-e "$Page_Dir/$pg.conf") {#Ok there is a page so # load it instead of home require "$Page_Dir/$pg.conf"; $page .= $page_content; } top_header("$title","","");#ok, now this is in # data.conf, it is the header and it uses CGI.pm's header() # start_html() etc. #ok, now below closes the table and creates the right menu # if any. right_menu() is defined in config.data $page .= qq~ </div /> </font /> </p />\n</td />~ . right_menu("in_table_cell","125",$overrideit) . end +_page_footer(); print $page; exit; # Exit system.
That is that. You can see the output at http://www.firstratehosting.com/t/index.cgi I'm not near finished with it, I'm trying to get the sessions to work, then I'm going to add an affiliate program to it, then finish the site.

I copied that from the other post. I have never used PerlMonks before, so I did not know it posted, as I could not find it, so I posted it again, then seen both :( oh well. I copied the code from my other post.


Thank you,
Richard.

Edit by tye, change PRE to CODE tags, add READMORE

Replies are listed 'Best First'.
Re: Re: Apache::Session::MySQL Help... Please
by perrin (Chancellor) on Dec 30, 2002 at 00:31 UTC
    I can't be sure without seeing the code for FRHWebDB::Session, but it looks to me like you have a scoping problem. You've made your session variable global, so it doesn't go out of scope until Perl shuts down. You should try making it lexically scoped (my) and let it go out of scope at the end of your CGI. Or you can do a quick fix by setting it to undef at the end.

    By the way, you don't need to explicitly exit at the end of a CGI, and it hurts portability to mod_perl, so leave that out.