Miguel has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

Under ASP (with VBScript in a global.asa file) and an IIS server I can get some information and do something when an application - and/or a session - starts or ends.

My question is as simples as: is there any way to do this in Perl and Apache with mod_CGI?

Thanks.
Miguel

Replies are listed 'Best First'.
Re: End of a user's session
by sgifford (Prior) on Dec 20, 2004 at 01:43 UTC
    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.
      "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.

Re: End of a user's session
by sasikumar (Monk) on Dec 20, 2004 at 05:42 UTC
Re: End of a user's session
by Arunbear (Prior) on Dec 20, 2004 at 12:15 UTC
    The Apache::ASP framework allows you to handle events such as application/session start/end, but requires mod_perl.
      I was afraid of that answer ;-)
Re: End of a user's session
by sauoq (Abbot) on Dec 20, 2004 at 01:37 UTC
    My question is as simples as: is there any way to do this in Perl and Apache with mod_CGI?

    My answer is as simple as: yes.

    -sauoq
    "My two cents aren't worth a dime.";