对于perl cgi脚本,这两者(在技术上)有什么不同?
#!/usr/bin/perl
use CGI;
$cgi = new CGI;
print $cgi->header(),
$cgi->start_html(),
$cgi->pre($cgi->param()),
$cgi->end_html();和
#!/usr/bin/perl
use CGI;
$cgi = new CGI;
print $cgi->header(),
$cgi->start_html(),
$cgi->pre($ENV{'QUERY_STRING'}),
$cgi->end_html();发布于 2010-01-30 03:53:47
假设HTTP请求如下:
GET my.cgi?foo=bar&baz=buz当在具有传统CGI接口的When服务器上运行时,环境变量QUERY_STRING将为foo=bar&baz=buz。环境变量将不是URL未转义的。用$cgi->pre(...)打印它只会用<pre></pre>标记包围env var (如果值是或被强制为空字符串,则只有一个<pre />标记)。
另一方面,假设一个没有参数的列表上下文,$cgi->param()将返回一个未转义的CGI参数名列表,在本例中为foo和bar。
(请注意,$cgi->pre(...)并不是超文本标记语言,因此$ENV{QUERY_STRING}可能只会因为一些跨站点脚本注入而危及您的cgi。)
发布于 2010-01-30 03:40:50
CGI对象上的param方法返回所有查询参数的列表,包括GET和POST参数。除非传入参数,在这种情况下,它会查找具有该名称的参数并返回值。
QUERY_STRING环境变量包含未解析的查询字符串。
如果您尝试过有问题的代码,这一点将非常明显。
Here是param的文档。
发布于 2010-01-30 03:42:26
根据CGI.pm的来源
#### Method: param
# Returns the value(s)of a named parameter.
# If invoked in a list context, returns the
# entire list. Otherwise returns the first
# member of the list.
# If name is not provided, return a list of all
# the known parameters names available.
# If more than one argument is provided, the
# second and subsequent arguments are used to
# set the value of the parameter.QUERY_STRING是由web服务器设置的,它只是uri中的查询字符串:you can read more about it here
https://stackoverflow.com/questions/2164632
复制相似问题