Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl CGI reading both url_param and param reliably

Tags:

url

cgi

perl

param

I'm writing a function that will list once all params passed to a CGI script, whether it be through a form sent with POST, the URL string, or both.

There are two functions for this:

param(): Despite the documentation, I have found this to read EITHER POSTed parameters from a form OR URL params only if there are no POST params.

On the other hand, url_param() will ever ONLY read params passed in through the URL string regardless of POST.


My function

sub post_and_url_param_keys{
  if(url_param){
    return [url_param, param];
  }else{
    return [param];
}

It can list all parameters if passed in with:

POST and URL params

POST params only

X URL params only (lists each key twice)

Is there a way to neatly fix this without having to check the name and value of each and every param pair for duplicates?

like image 822
JD. Avatar asked Dec 02 '25 19:12

JD.


1 Answers

A slightly improve method would be to check if request_method() eq 'POST'. You may still get duplicate parameter names if you query string and post both contain the same parameter name.

like image 76
Ven'Tatsu Avatar answered Dec 05 '25 11:12

Ven'Tatsu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!