For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > December 2004 > Using Apache::Session for storing form data as opposed to database columns









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using Apache::Session for storing form data as opposed to database columns
ioneabu@yahoo.com

2004-12-28, 3:57 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com