Perl 设置cookie并重新加载的CGI脚本

Perl 设置cookie并重新加载的CGI脚本,perl,cgi,Perl,Cgi,我有一个CGI脚本,它在URL中获取一些参数,并显示一个表单。 当用户提交表单时,表单中的信息保存在cookie中。 现在,在提交时,我希望调用相同的URL,包括最初使用的参数 示例:可能更清楚一些: 有人这样叫我: www.mysite.com/script.cgi?name=nec&mail=necnec 在此页面上,用户可以选择颜色(红色、黄色、绿色)。 按下submit按钮时,我希望我的页面被调用,如下所示: www.mysite.com/script.cgi?name=nec&mail

我有一个CGI脚本,它在URL中获取一些参数,并显示一个表单。 当用户提交表单时,表单中的信息保存在cookie中。 现在,在提交时,我希望调用相同的URL,包括最初使用的参数

示例:可能更清楚一些: 有人这样叫我:

www.mysite.com/script.cgi?name=nec&mail=necnec

在此页面上,用户可以选择颜色(红色、黄色、绿色)。 按下submit按钮时,我希望我的页面被调用,如下所示:

www.mysite.com/script.cgi?name=nec&mail=nec&color=green

我是怎么做到的


谢谢

名为script.cgi的脚本可能如下所示

script.cgi
#!C:\Perl\bin\Perl.exe
严格使用;
使用警告;
使用CGI;
my$query=新CGI;
我的$p|u name=$query->param('name')| |“无名称”;
my$p|u mail=$query->param('mail')| |“无电子邮件”;
打印$query->header(“文本/html”);
打印
#!C:\Perl\bin\perl.exe
use strict;
use warnings;  
use CGI;  
my $query = new CGI;  
my $p_name=$query->param('name')|| "NO Name";  
my $p_mail=$query->param('mail')|| "NO Email";  
print $query->header( "text/html" );  
print <<START_HERE;  
       <html>  
       <head>  
           <title>Your First CGI Script</title>  
       </head>  
       <body>  
           <h1>This is a script Web page</h1>  
           <p>  
              <form name='testform' method='get' action='test.pl'>  
              <input type="hidden" name="name" value=$p_name />  
              <input type="hidden" name="mail" value=$p_mail /> 
              <select name='color'>  
                      <option value="red">Red</option>  
                      <option value="green">Green</option>  
                      <option value="white">White</option>  
                      <option value="yellow">Yellow</option>  
               </select>  
               <input type='submit' value='submit' name="submit" />  
               </form>  
            </p>  
          </body>  
          </html>  
          START_HERE 
    #must have a line after "START_HERE" or Perl won't recognize  
    #the token 
#!C:\Perl\bin\perl.exe
use strict;  
use warnings;  
use CGI;  
my $query = new CGI;  
my $cookie_color=$query->cookie('color');
my $name=$query->param('name')|| "NO Name";  
my $mail=$query->param('mail')|| "NO Email";  
my $color=$query->param('color')|| $cookie_color || "NO color";
my $cookie = $query->cookie(-name=>'color',
    -value=>$color_value,
    -expires=>'+4h',
    -path=>'/');
print $query->header( "text/html" );  
print $query->header(-cookie=>$cookie);
print <<START_HERE;  
         <html>  
           <head>  
              <title>Script to check the Parameters</title>  
           </head>  
           <body>  
              <h1>This is a test Web page</h1>  
              <p>Name: $name</p>  
              <p>Mail: $mail</p>  
              <p>Color: $color</p>  
           </body>  
        </html>  
       START_HERE   
#must have a line after "START_HERE" or Perl won't recognize  
#the token