[ale] ? and QUERY_STRING
Michael B. Trausch
mike at trausch.us
Tue Aug 21 11:59:22 EDT 2007
Warren Myers wrote:
> the http string should look something like this:
>
> http://server.some.tld/cgi-bin/script.pl?firstvar=73&secondvar=shpage
> <http://server.some.tld/cgi-bin/script.pl?firstvar=73&secondvar=shpage>
>
> is that what you're looking for?
>
The query strings show up as an environment variable, too, by the way.
I am not sure if Perl has functionality to handle this directly by
importing that stuff into Perl variables or anything like that, but I
know that (for example) when writing a CGI script in bash, you can
simply use the QUERY_STRING environment variable to parse your args and
act on them accordingly. IIRC, for the URL provided above, the
QUERY_STRING environment variable would be set as follows:
firstvar=73&secondvar=shpage
Then, you just parse the string into key=value pairs by breaking them at
the & symbol (example in bash):
cgi_args=$(echo ${QUERY_STRING}|tr \& '\n')
And then you can import them as shell varables, if you want (note: this
can be insecure for crafted variables, so you'll want to do additional
checks to make sure that variables like PATH and the like aren't being
passed in):
for i in $cgi_args; do eval $i; done
In this instance, after you have run the eval line, you would have
variables in your shell that would be $firstvar and $secondvar. Here is
what I did in a local shell to demonstrate:
mbt at sage:~$ QUERY_STRING='firstvar=73&secondvar=shpage'
mbt at sage:~$ cgi_args=$(echo ${QUERY_STRING}|tr \& '\n')
mbt at sage:~$ echo $cgi_args
firstvar=73 secondvar=shpage
mbt at sage:~$ for i in $cgi_args; do eval $i; done
mbt at sage:~$ echo $firstvar
73
mbt at sage:~$ echo $secondvar
shpage
mbt at sage:~$
HTH,
Mike
--
Michael B. Trausch Internet Mail & Jabber: mike at trausch.us
Phone: (404) 592-5746 x1 http://www.trausch.us/
Mobile: (678) 522-7934 VoIP: 6453 at sip.trausch.us, 861384 at fwd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
More information about the Ale
mailing list