Friday, July 01, 2011

setting cookies & doing redirects in clunky frameworks

Sometimes when doing operation and maintenance coding you find yourself working a framework where the original developers left some functionality out and adding the "right way" is just not worth the effort.  In these types of scenarios it is good to know about "http-equiv" meta tags.

  • Setting cookies & redirection
sub upd_server_type_filter {
        my $server_type_filter = $cgi->param('server_type_filter_text_area');

        # a clunky solution for a clunky framework
        print "<meta http-equiv=\"Set-Cookie\" content=\"server_type_filter=$server_type_filter; path=/; expires=\"\"\">\n";
        print "<meta http-equiv=\"refresh\" content=\"0\">\n";
}

  • Getting the  cookie
sub get_server_type_filter {
        my @filter;

        # fetch cookies
        my %cookies             = CGI::Cookie->fetch;
        my $server_type_filter  = $cookies{'server_type_filter'}->value if $cookies{'server_type_filter'};
        $server_type_filter =~ s/\s//g;
        @filter = split /,/, $server_type_filter;
        return @filter;
}

No comments:

Post a Comment