Using Apache::Session for storing form data as opposed to database columns

Discussion in 'Perl Misc' started by ioneabu@yahoo.com, Dec 28, 2004.

  1. Guest

    I realize that searching for data this way is not as efficient, but it
    makes it easy if a form changes, there is no need to change a database
    structure. I was wondering if others do it this way, saving all of
    their web form data to a hash and putting it in Apache::Session to call
    out later with the session id number. It's like leaving your clothes
    at the dry cleaners and taking a ticket home to retrieve the clothes at
    a later time.

    Here is a sub I wrote to handle the work:

    sub session_handler
    {
    my ($dbh,$hash_ref,$sess_id_ref,$action) = @_;
    my %session;
    tie %session, 'Apache::Session::MySQL', $$sess_id_ref,
    {Handle=>$dbh, LockHandle=>$dbh};
    $$sess_id_ref = $session{'_session_id'};
    if ($action =~ /write/i)
    {$session{$_} = ${$hash_ref}{$_} for keys %{$hash_ref}}
    elsif ($action =~ /read/i)
    {${$hash_ref}{$_} = $session{$_} for keys %session}
    elsif ($action =~ /delete/i) {tied(%session)->delete}
    }


    the hash referenced by $hash_ref is either filled with data or is to be
    filled with data depending on the value of $action. Same with
    $sess_id_ref.

    It is tested and appears to work fine. I started with a big mess of
    code and tried to clean it up by using statement modifiers.

    Any advice on code would be appreciated and on the soundness of the
    overall method of using Apache::Session for storing fairly large
    amounts of important data from html forms.

    Thanks,

    wana
    , Dec 28, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FrZXQgTXVuZHJh?=

    Temporarirly storing web form data to be inserted into Database ?

    =?Utf-8?B?U2FrZXQgTXVuZHJh?=, Mar 31, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    2,102
    Joseph Byrns
    Apr 1, 2005
  2. hfk0
    Replies:
    5
    Views:
    667
  3. Replies:
    5
    Views:
    580
  4. Jonathan Wood
    Replies:
    1
    Views:
    498
    Jonathan Wood
    Jun 2, 2008
  5. baptiste Auguié

    storing and manipulating columns of data

    baptiste Auguié, Jun 30, 2007, in forum: Ruby
    Replies:
    4
    Views:
    129
    Axel Etzold
    Jun 30, 2007
Loading...

Share This Page