如何解析和回显 CGI 查询字符串参数?

发布于 2024-08-20 22:38:21 字数 700 浏览 3 评论 0原文

我想使用 URL 中的系统请求参数在服务器上执行命令。我正在运行服务器。

在浏览器中->> //localhost:9009/?comd 它显示我放入代码中的目录中的文件列表

if (/comd/i )        { print  $client `dir`;      }

如何解析请求参数?例如:

http://localhost:9009/?comd&user= kkc&[电子邮件受保护]

我会喜欢回来->> 您好用户请确认您的电子邮件[电子邮件  ;protected]

如何解析url中的请求参数?

I would like to execute a command on the server by using the system request parameters in the URL. I am running the server.

In the browser ->> //localhost:9009/?comd which is displaying the list of files in the directory as i placed in the code

if (/comd/i )        { print  $client `dir`;      }

How I can parse the request parameters? For example:

http://localhost:9009/?comd&user=kkc&[email protected]

I would like to return -->> hellouser please confirm your email[email protected]

How can I parse the request parameters in the url?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬心 2024-08-27 22:38:21

use CGI;

my $cgi = CGI->new();

my $user = $cgi->param( "user" );
my $mail = $cgi->param( "mail" );

print( "Hello $user please confirm your email $mail\n" );

use CGI;

my $cgi = CGI->new();

my $user = $cgi->param( "user" );
my $mail = $cgi->param( "mail" );

print( "Hello $user please confirm your email $mail\n" );
我一直都在从未离去 2024-08-27 22:38:21
#!/usr/bin/perl
$|++;                              # auto flush output

use CGI;                           # module that simplifies grabbing parameters from query string
use HTML::Entities;                # for character encoding
use strict;                        # to make sure your Perl code is well formed

print qq{Content-type: text/html\n\n};  # http header b/c outputting to browser

   main();                         # calling the function

   sub main{
      my $cgi    = new CGI;        # store all the cgi variables
      # the following stores all the query string variables into a hash
      #   this is unique because you might have multiple query string values for
      #   for a variable. 
      #   (eg http://localhost/[email protected]&[email protected]&[email protected] )
      my %params = map { $_ => HTML::Entities::encode(join("; ", split("\0", $cgi->Vars->{$_}))) } $cgi->param;

      #Input: http://localhost:9009/?comd&user=kkc&[email protected]
      #Output: Hello kcc please confirm your email [email protected]

      print <<HTML;
      <html>
         <head>
            <style type="text/css">.bold{font-weight:bold}</style>
         </head>
         <body>
            Hello <span class="bold">$params{user}</span> please confirm your email <span class="bold">$params{mail}</span>
         </body>
      </html>
HTML

      return 1;
   }

我希望这有帮助。

#!/usr/bin/perl
$|++;                              # auto flush output

use CGI;                           # module that simplifies grabbing parameters from query string
use HTML::Entities;                # for character encoding
use strict;                        # to make sure your Perl code is well formed

print qq{Content-type: text/html\n\n};  # http header b/c outputting to browser

   main();                         # calling the function

   sub main{
      my $cgi    = new CGI;        # store all the cgi variables
      # the following stores all the query string variables into a hash
      #   this is unique because you might have multiple query string values for
      #   for a variable. 
      #   (eg http://localhost/[email protected]&[email protected]&[email protected] )
      my %params = map { $_ => HTML::Entities::encode(join("; ", split("\0", $cgi->Vars->{$_}))) } $cgi->param;

      #Input: http://localhost:9009/?comd&user=kkc&[email protected]
      #Output: Hello kcc please confirm your email [email protected]

      print <<HTML;
      <html>
         <head>
            <style type="text/css">.bold{font-weight:bold}</style>
         </head>
         <body>
            Hello <span class="bold">$params{user}</span> please confirm your email <span class="bold">$params{mail}</span>
         </body>
      </html>
HTML

      return 1;
   }

I hope this helps.

GRAY°灰色天空 2024-08-27 22:38:21
use CGI;
use HTML::Template;

my $cgi = CGI->new;

my $html = qq{
    <!DOCTYPE HTML>
    <html>
    <head><title>Confirmation</title></head>
    <body><p>Hello <TMPL_VAR USER ESCAPE=HTML>. 
    Please confirm your email <TMPL_VAR MAIL ESCAPE=HTML></p></body>
    </html>
};

my $tmpl = HTML::Template->new(scalarref => \$html, associate => $cgi);
print $cgi->header('text/html'), $tmpl->output;
use CGI;
use HTML::Template;

my $cgi = CGI->new;

my $html = qq{
    <!DOCTYPE HTML>
    <html>
    <head><title>Confirmation</title></head>
    <body><p>Hello <TMPL_VAR USER ESCAPE=HTML>. 
    Please confirm your email <TMPL_VAR MAIL ESCAPE=HTML></p></body>
    </html>
};

my $tmpl = HTML::Template->new(scalarref => \$html, associate => $cgi);
print $cgi->header('text/html'), $tmpl->output;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文