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

I've got an authentication perl cgi I've written. Basically all my pages check for an authentication cookie. So if you navigate to mypage.cgi?key=1&foo=bar and there's no auth. cookie, it passes its own URL to authenticate.cgi?destination=$query->url(-query=>1)

The problem is, authenticate.cgi is only receiving destination=mypage.cgi?key=1 and is losing the second bit &foo=bar.

I suspect that the first parameter is going through, and the second parameter is getting lost (and that all parameters after the first would be lost) but I'm not sure how to fix the problem. I thought cgi.pm was supposed to automatically escape things in a situation like this.

Thanks!

Replies are listed 'Best First'.
Re: passing URL with parameters
by Aristotle (Chancellor) on Aug 30, 2004 at 21:27 UTC

    It is not getting lost. Your URL ends up being authenticate.cgi?destination=mypage.cgi?key=1&foo=bar, which makes foo=bar parameters to authenticate.cgi rather than part of its destination parameter.

    You want something like

    use URI::Escape; print( "authenticate.cgi?destination=", uri_escape( $query->url( -query => 1 ) ), );

    Or you could use URI to build the URL which transparently handles all escaping as necessary:

    use URI; my $dest = URI->new( "authenticate.cgi" ); $dest->query_form( destination => $query->url( -query => 1 ) ); print $dest->as_string;

    In either case, you get this properly escaped result: authenticate.cgi?destination=mypage.cgi%3Fkey%3D1%26foo%3Dbar

    Makeshifts last the longest.