English 中文(简体)
Access lect >
原标题:Accessing multiple <select>-ed parameters with Perl CGI
  • 时间:2012-04-24 17:13:47
  •  标签:
  • html
  • perl
  • cgi

我正在使用Perl CGI模块。 如果我有这样的超文本的话,

<select multiple name="FILTER_SITE">
  <option>1</option>
  <option>2</option>
</select>

and submit my form I can get something like this in the URL: [..] FILTER_SITE=1&FILTER_SITE=2

缩略语

我如何利用这两者(在这种情况下)? “哈克”是我的第一个想法,它使参赛人感到羞愧,然后我再一次在农研组中vers。 页: 1

有数据:Dumper, 有趣

print “<pre>>Dumper ($cgi->param ( FILTER_SITE ) . “</pre>”

$VAR1 =  1 ;
$VAR2 =  2 ;
最佳回答

<><>>> 注:现有文件(截至2020年5月29日)说,这种方法可能造成安全方面的弱点。 请回答如下:。

<代码>第方法在列表中提供了单一数值和(可能)多重数值。 阅读here

因此,如果你把你的法典改为例如,

my @FILTER_SITE   = $cgi->param( FILTER_SITE );

然后,阵列将包含选择的所有选定价值观。

如果能更好地适用你的法典,你也可以写一下。

for my $FILTER_SITE ($cgi->param( FILTER_SITE )) {
  :
}
问题回答

我知道这是一个老的职位,但从这个问题得到回答以来,没有什么变化。 我想把最新信息放在首位,特别是因为现已接受的答案被视为安全脆弱性。 CGI.pm 文件:

{Warning - calls param () in list context can lead to Vulnerability if You do not sanitiseuser submissions as it is possible to jection other param keys and Value into You Code. 正因为如此,有多段(a)方法,以明确一个清单正在退回,指出(b)段仍然可以列在清单中,并将返回一个清单,以备兼容性。

建议使用“条码”方法,而不是“多面”方法。

宗教价值实例

    #!/usr/bin/perl

    use Encode;

    print "Content-Type: text/html; charset=UTF-8

";

    if($ENV{ REQUEST_METHOD } eq "POST") {
      read(STDIN, $querystring, $ENV{ CONTENT_LENGTH });
     print "<h1>POST</h1>";
    } else {
      print "<h1>GET</h1>";
      $type = "display_form";
      $querystring = $ENV{ QUERY_STRING };
    }

    print "<p>$querystring</p>";

    if (length ($querystring) > 0){
      @pairs = split(/&/, $querystring);
      foreach $pair (@pairs){
           ($name, $value) = split(/=/, $pair);
           $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
           $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
           if (exists $in{$name}) {
             $value = "$value,$in{$name}";
           }
           $in{$name} = $value;
      }
    }

   foreach my $val (sort keys %in) {
     print "<p>$val: $in{$val}</p>";
   }




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!