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

All I have noticed that when writing a simple form in CGI.pm
when you submit the form the values are passed onto the URL Bar of the browser.

So you end up getting something like
http://www.domain.com/cgi-bin/app.pl?username=ben&password=test

Is there a way to stop information being passed onto the browser search bar.

Replies are listed 'Best First'.
Re: CGI Parsing information on URL Bar
by gellyfish (Monsignor) on Mar 31, 2005 at 07:58 UTC

    I would suggest that you see the HTTP Specification in particular with reference to the difference between the GET and POST request methods.

    /J\

      And while you're reading that, note that using POST just to "hide" the data is an abuse of HTTP. POST should be used for requests that have side-effects: amongst other things that means that a GET request with a given URL should usually give the same response (within some reasonable time-limit), while a POST request doesn't have to. It also explains why conforming browsers should give a warning when you try to reload a page that was produced from a POST request.

      Of course. for logging in to a system, a POST request is appropriate.

Re: CGI Parsing information on URL Bar
by inman (Curate) on Mar 31, 2005 at 08:18 UTC
    You need to POST your data rather than GET it as you are at the moment. Using GET during form development can be useful since you can see what is going on. You can then switch to POST once you are ready. The other major difference is that POSTed data can exceed the 2k maximum length of a URL.

    The great thing about using CGI.pm and relatives is that when it comes to script processing, there is no difference between data submitted by either GET or POST.

Re: CGI Parsing information on URL Bar
by gopalr (Priest) on Mar 31, 2005 at 09:17 UTC

    GET

    If you setup your <form> to use the GET method, then a browser will encode all of the form variables into a URL and pass them onto the web server. You can see the variables and their values in the location bar.

    So, Use POST request

Re: CGI Parsing information on URL Bar
by PodMaster (Abbot) on Mar 31, 2005 at 08:05 UTC
    All I have noticed that when writing a simple form in CGI.pm when you submit the form the values are passed onto the URL Bar of the browser.
    Compare this form to the one you have
    #!/usr/bin/perl -w use CGI ':all'; print header, start_html, start_form, textarea(-name => 1), submit, end_form, end_html; __END__
    This is the default form action.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.