Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Oops! (Query String messed up)

by Chady (Priest)
on Mar 12, 2001 at 13:07 UTC ( #63782=perlquestion: print w/replies, xml ) Need Help??

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

I'm working on a new navigation system for my website, kinda like the one here (but not so smart). so all my links look something like : now to control things, all outside links are specified like that (for logging):

The problem occured when I wanted to link to a page with a query like, so the link was like : You get the idea

the URL query gets messed up, is there a way to get around this? or should I substitute the ampersands "&" with some other character, and then s/// them when redirecting?

any thoughts??

Chady |

Replies are listed 'Best First'.
(dkubb) Re: (2) Oops! (Query String messed up)
by dkubb (Deacon) on Mar 12, 2001 at 14:20 UTC

    Well, you could use a regex to URL encode all the elements in your URL parameters, then join them together into a single query string.

    But, there is a much simpler way, using the CPAN module URI.

    Below is an example program using URI that does something similar to what you want:

    #!/usr/bin/perl -w use strict; use URI; use constant BASE_URL => ''; use constant REFERER => ''; my $uri = URI->new(BASE_URL); $uri->query_form( location => 'Redirect', URL => REFERER, referer => 'Links', ); print $uri;

    A well formed URL will be printed out, and any parameters will be URL encoded properly.

    A nice bonus is that the code made with URI is easy to read and hides all the potentially messy URL construction/encoding details from you. I almost never work with URL's by hand any longer since I started to use this module.

Re: Oops! (Query String messed up)
by merlyn (Sage) on Mar 12, 2001 at 14:46 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://63782]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2023-09-24 16:50 GMT
Find Nodes?
    Voting Booth?

    No recent polls found