in reply to Suggestion- How to serialize a cgi object?

The more I contemplate this, the more I think what you are really looking for is the ability to store session data or user data. Are you using any kind of session management right now? Do you require users to log in?

If not, here's how things could work if you implemented users and user data: When users visited your site they would log in and receive a cookie identifying who they are (their login id). When they uploaded a file, those files would be placed in a directory identified by their login id. When they later visited your site, you can retrieve those files by getting their login id from the login cookie and consulting the appropriate directory. You can store other data (such as POST data) using the FreezeThaw module, but I still would transfer only the data you really need to save (i.e. the parameter data) to a new hash and serialize that to a file instead of serializing the entire CGI object.

Am I on the right track here? If so, there are a lot of modules to help you manage web sessions. For instance, have a look at CGI::Session.

Replies are listed 'Best First'.
Re^2: Suggestion- How to serialize a cgi object?
by pffan239 (Beadle) on May 12, 2008 at 12:17 UTC

    pc88mxer, belated thanks for the first follow up.

    Yes, users need to log in. I'm already using CGI::Session (via CGI::Application::Plugin::Session) to manage sessions. I'm using a session variable with expiration to keep track of their activity and time them out after certain period of time.

    Here's what I'm trying to accomplish, in short... when a user's login goes inactive and they try to continue by clicking a link or submitting a form, I want to capture all the request details (ie, everything in the CGI object at the time), store it, prompt the user to reauthenticate, and then (after successful re-authentication) play back the original request using the stored request details. The whole goal is to prevent to user from losing data in form that may take a while to file in. Pretty reasonable?

    I've actually got everything that worked out except for when the CGI object to be stored is from a POST that happened to have a file upload field.

    I think your suggestion to store the actual POST data directly or save off the files manually (keyed by session_id) is where was headed originally. I was just wondering if I was missing something simpler. Been working on this stuff for a while, so I was afraid that I might be missing something obvious.

    I'm not sure which of these two alternatives I like better:

    1. If I store the actual POST data, I need to have separate routines to handle GETs and POSTs (serializing the CGI object added a nice layer of abstraction.) Getting the saved POST data back into a new CGI object is also a little tricky (but do able).
    2. Scanning through the incoming CGI to save off files manually isn't difficult. Probably have to do something tricky to get files back into the CGI when its restored later. I'm pretty sure you can't do something like $cgi->param('uploadFieldName',$pathToFile). that would be way too easy.