Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

passing args in html

by daddyo (Initiate)
on Jan 27, 2002 at 00:00 UTC ( #141821=perlquestion: print w/replies, xml ) Need Help??
daddyo has asked for the wisdom of the Perl Monks concerning the following question:

how/is it possible to pass arguments to a cgi script in html: <img src = "skrit.cgi 1"> so that argv[0]=1? it works ok without the arg ... <img src = "skrit.cgi">

Replies are listed 'Best First'.
Re: passing args in html
by BazB (Priest) on Jan 27, 2002 at 00:14 UTC

    I'm not sure if this is actually a Perl/CGI question - it's more HTTP and HTML - if you want to pass arguments to another page use:

    <a href="random_page.cgi?arg1=foo&arg2=bar&arg3=baz">Random Page</a>
    <img src="random_page2.cgi?arg1=foo&arg2=bar&arg3=baz">
    You get the idea.

    It's the same idea whether it's a perl script, php page, ASP *Gaaak* page, or whatever.
    For an example of this, look at almost any page in the Monastery...

    Pulling out the arguments you pass to your script in this fashion (or via the POST method) will require the modules belg4mit mentioned.

    Update: wog++. Taking wog's post a bit further, it's probably a good idea to do URL Escaping - pass all strings like the URLs I've written above through URI::Escape or CGI's escape() in order to correctly handle difficult arguments.
    It's something I've got into the habit of - IMHO it's worth having a sub urlEncode in bigger systems.

      The &s in URLs should be written &amp; and &#38; in HTML. (reference). If the CGI, etc. you are calling supports it, it would probably be cleaner to use ; instead of & as the parameter seperator. ( supports this.)
      Thanks for sharing your wisdom, Masters of Perl.
Re: passing args in html
by belg4mit (Prior) on Jan 27, 2002 at 00:06 UTC
    It's possible (IIRC), but you'd be much better off boning up on CGI and using PATHINFO or GET. See CGI and CGI::Lite.

    UPDATE: Additionally, passing arguments directly could be a Bad Thing. Passing parameters via another means requires additional processing to extract them, this is a Good Thing because while you are doing this you might as well go "whole hog"(?) and untaint and validate the data. Just as a general rule.

    perl -pe "s/\b;([st])/'\1/mg"

      I'd also go even further and recommend studying basic html and web forms. OReilly's HTML book is a good start.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://141821]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-06-23 09:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.