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

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; }

Replies are listed 'Best First'.
Re: Please help me... Apache::Session::MySQL
by powerhouse (Friar) on Dec 28, 2002 at 19:34 UTC
    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.