Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting values from URL?

Status
Not open for further replies.

mrdance

Programmer
Apr 17, 2001
308
SE
I am new to Perl and I am using a cgi-module. I am using $cgi->param('nameoffield') to get a value from a field but how do I get it from the URL? (
Thanks Henrik
 
The parameter your passing would be in an Environment variable. Off the top of my head I'm thinking QUERY_STRING, but I could be wrong about that.
 
No, you are not wrong about that. The only difficulty is that $ENV{'QUERY_STRING'} may be encoded the same way as other form data, which can make it a pain to parse. Seems to me that I read in the CGI.PM documentation that you could get parameters from both POST and QUERY_STRING using similar techniques, but I'm not sure about the details. Check the CGI.PM documentation, or I'll have a look later if I get time.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Same exact technique - CGI.pm uses the "param" method to get the value of a variable, whether it comes in to the script via GET(or QUERY_STRING) or POST.

You can read the perldocs on the CGI.pm module by doing

perldoc CGI

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
I know the technique is the same whether it's via get OR post, but what about via get AND post? I got the impression that's what mrdance wanted to do.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
My fault, I had some problems before, but as tsdragon says, it's the same method to use.

Thanks
 
from the CGI.pm docs in section "Mixing POST and URL Parameters".

-- clip
It is possible for a script to receive CGI parameters in the URL as well as in the fill-out
form by creating a form that POSTs to a URL containing a query string (a ``?'' mark
followed by arguments). The param() method will always return the contents of the
POSTed fill-out form, ignoring the URL's query string. To retrieve URL parameters,
call the url_param() method. Use it in the same way as param(). The main difference
is that it allows you to read the parameters, but not set them.

Under no circumstances will the contents of the URL query string interfere with
similarly-named CGI parameters in POSTed forms. If you try to mix a URL query
string with a form submitted with the GET method, the results will not be what you
expect.
-- end clip

HTH


keep the rudder amid ship and beware the odd typo
 
Thanks, I knew I remembered reading that! Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top