in reply to End of a user's session

Perl and the CGI module don't have a builtin concept of sessions like ASP does. You have to manage the sessions yourself, and so it's fairly easy: when you create a new session run some code, and when you destroy a session run some code. A straightforward and reliable module for managing sessions is CGI::Session.

Replies are listed 'Best First'.
Re^2: End of a user's session
by Miguel (Friar) on Dec 20, 2004 at 10:35 UTC
    "A straightforward and reliable module for managing sessions is CGI::Session."

    Indeed.
    I've been using this module for 2 years now.
    Unfortunately, I still can't (or don't know how to do it) start some code when a session is destroyed when one user closes his/her browser. On the other hand, I know how to handle $session->delete() and all the functions.

    Suppose I have a program that writes some info in a txt file, containing the $session->id() and some more stuff.
    If the user presses the logoff button I delete that file. But if the user closes his/her browser's window... the connection with the program is closed and the session is destroyed, but the file remains intact.

    How can I delete a temporary file associated with a user's session ID when he/she closes his/her browser?

      How can I delete a temporary file associated with a user's session ID when he/she closes his/her browser?

      It is very difficult (impossible?) to do that in a reliable way. If the temporary files (or database entries, or whatever you use for session tracking) start to bother you, you should set a session timeout. If you do not hear from the user for, say, two hours, delete the file. Can be done with a cron job.

        How can I delete a temporary file associated with a user's session ID when he/she closes his/her browser?
        It is very difficult (impossible?) to do that in a reliable way.
        It's impossible. There is no real implementation of "the end of a session" - there is only a session ID that's passed on every request to the site (if at all). All you can do is run some code when the session times out, and you'll never know for sure wether a user has closed his browser, disabled cookies, moved to another site, or had his computer bust into flames.