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

Ok, bit of a problem

Using cgi, and the following code:

Using readmore coz theres a lot

use CGI; use Class::Date; #Own Modules - to see if the user exists? use SuperClan::Database::Users; sub setup { my $self = shift; $self->start_mode('email'); $self->run_modes([qw/email email_member/]); } sub email { my $self = shift; my $html_template = $self->param('html_template'); my $cgi = CGI->new; my $session = $cgi->param('session'); my $user_status; my $return; my $output; if ( $session eq "" ) { $self->header_props( -url => "/" ); $self->header_type('redirect'); } else { #session exists run std session app $return = SuperClan::Application::SuperClan::session($session); ($user_status, $session) = split /b/, $return; if (($user_status eq "logged_out")||($user_status eq "hacking_attemp +t")) { $html_template->process('user', { wrapper => $self->wrapper(), session => $session, user_status => $user_status, }, \$output) || die $html_template->error; } else { $html_template->process('email', { wrapper => $self->wrapper(), session => $session, user_status => $user_status, process => "email", }, \$output) || die $html_template->error; } return $output; } } sub email_member { my $self = shift; my $errs = shift; my $html_template = $self->param('html_template'); my $cgi = CGI->new; my $session = $cgi->param('session'); my $member = $cgi->param('member'); my $user_status; my $return; my $output; my @members; if ( $session eq "" ) { $self->header_props( -url => "/?session=".$session ); $self->header_type('redirect'); } else { #session exists run std session app $return = SuperClan::Application::SuperClan::session($session); ($user_status, $session) = split /b/, $return; if (($user_status eq "logged_out")||($user_status eq "hacking_attemp +t")) { $html_template->process('user', { wrapper => $self->wrapper(), session => $session, user_status => $user_status, }, \$output) || die $html_template->error; } else { @members = SuperClan::Database::Users->retrieve_all; $html_template->process('email', { wrapper => $self->wrapper(), session => $session, user_status => $user_status, process => "email_member", members => \@members, member => $member, errors => $errs, }, \$output) || die $html_template->error; } return $output; } }/ 1;

And using the apporpriate rewrite engine and rules in the htaccess file, why can I not send the ?session=x in the address line to the fucntions which are not the start mode

To be specific the start mode (email) can capture the session using $session=$cgi->param('session'); but the other function (email_member), can not capture the session from the address line, when using /email_member/?session, unless i use ?rm=email_member&session=x.

.htaccess

RewriteEngine on RewriteRule email_member/$ ?rm=email_member SetHandler perl-script PerlHandler SuperClan::Application::Email->handler

Yours
Barry Carlyon barry@barrycarlyon.co.uk

Replies are listed 'Best First'.
Re: CGI, and fetching things from the 'address line'
by Corion (Patriarch) on Jun 23, 2006 at 12:57 UTC

    I don't know much about Apache and mod_rewrite, but your rewrite rule

    RewriteEngine on RewriteRule email_member/$ ?rm=email_member

    will never rewrite any URL that has something after it:

    http://localhost/email_member/ -> http://localhost/?rm=email_member http://localhost/email_member/x -> <unchanged>

    I guess you want to expand your rewrite rule:

    RewriteEngine on RewriteRule email_member/(.*)$ ?rm=email_member;session=$1

    ... except that I don't know (and am too lazy to look up) the mod_rewrite syntax for capturing and rewriting stuff.

Re: CGI, and fetching things from the 'address line'
by leocharre (Priest) on Jun 23, 2006 at 14:29 UTC

    Corion is a charm with that rewrite rule hint. It's goodwill that like that, which gives this place the authority it has.

    The other thing is- if you're concerned at all about "hacking attempts etc.. Consider CGI::Validate , the coding interface is a wonder. And use Taint- untainting is not sooo much of a pain.