in reply to Re: Please help me... Apache::Session::MySQL
in thread Please help me... Apache::Session::MySQL

thank you both, very much!

I will join the mailing list, and post the problem there too. I think I did narrow it down...

I used Shell to run the site, and I get these errors:

[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 value at /usr/lib/perl5/site_perl/5.6.1/Apache/Session.pm line 508 during 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~ &lt;/div /> &lt;/font /> &lt;/p />\n&lt;/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.

It still does not work though...

If you need to also see the Session.pm code let me know, I'll post that too.

Thank you ever so kindly.
Richard

edited: Sat Dec 28 17:57:25 2002 by jeffa - broke out the Mop of Formatting +42 on this one

Replies are listed 'Best First'.
Re: Re: Please help me... Apache::Session::MySQL
by iguanodon (Priest) on Dec 28, 2002 at 18:55 UTC
    Hmmm... this is even more complicated than I thought. Your session handling is wrapped in another module. What is FRHWebDB::Session? Is that your module or someone else's?

    The first thing I would recommend is adding a time stamp to the session every time the script is invoked.

    Also, I don't see how your session is being untied. Maybe this is buried in FRHWebDB::Session but I suspect it's being left to happen when the Apache::Session object is cleaned up automatically at the end of the script. This may work most of the time but as the Apache::Session docs say, you should explicitly call undef or untie from your script.

    I use an END block in my "index" script to handle this:

    END { $session->{'timestamp'} = localtime(); undef $session; $dbh->disconnect; }
      Yes, it is a little complex. The FRHWebDB::Session is my module, I learned it from the book "Perl and MySQL for the web" by Paul DuBois.

      I actually have the session untie, ONLY when the user clicks logout, which is pg=quit.

      The code is this:
      if ($in{pg} eq "quit" && defined($sess_ref)) {
          if ($sess_ref->attr ("remember_me") == 1) {
              $sess_ref->attr ("loggedin", 0);#just change it to 0
              $message = qq~You have been Logged Out$nname_ws!

      ~;#$nname_ws is their nickname with a # space in front of it, if no nick name then it's blank # (Out!) } else { Delete_Session_Forever($sess_ref); } } Here is the code in data.conf for the Delete_Session_Forever()... sub Delete_Session_Forever { $sess_ref = shift; $sess_ref->delete(); # Destroy session for good # Create cookie that tells browser to destroy the one it's storing $cookie = cookie (-name => "session_id", -value => $sess_ref->session_id(), -path => url (-absolute => 1), -expires => "-1d"); # Expire Yesterday $loggedin = 0; $sess_ref->attr ("loggedin", 0); $message = qq~You have been Logged Out<br>AND<br>Your Session Has been Deleted!<br><br>~; }

      That is pretty much when it tells it to quit.

      If you need to see the FRHWebDB::Session code let me know, I'll post it.

      Thank you!
      Richard
        IMHO, you should explicitly call undef or untie on your session hash after every invocation of your script, to make sure Apache::Session will write the session info to the database. I think depending on this happening automagically is hit or miss at best.

        Note that calling undef or untie will not remove the session record from the table, there is a delete method for that. Calling the delete method may be what you want in your logout handler.