为什么此密码检查不能按预期工作?

为什么此密码检查不能按预期工作?

问题描述:

我想从php中扩展。这是一个基本的问题,我并不能看着办吧......为什么此密码检查不能按预期工作?

password.pl

#!/usr/bin/perl 

use CGI; 
$q = new CGI; 

print "Content-type:text/html\r\n\r\n"; 
print '<html>'; 
print '<head>'; 
print '<title>Card</title>'; 
print '</head>'; 
print '<body>'; 
print '<FORM METHOD=POST ACTION=/card.pl>'; 
print '<INPUT TYPE=password NAME=password SIZE=25>'; 
print '<input type=submit value=Submit>'; 
print '</FORM>'; 
print '</body>'; 
print '</html>'; 

1; 

card.pl

#!/usr/bin/perl 

use CGI; 
$q = new CGI; 

$password = $q->param("password"); 
print $password; 
if ($password == pass) 
{ 
    print 'Yup'; 
} 
else 
{ 
    print 'Wrong Password'; 
} 


1; 

没有正在经过距密码card.pl .pl表单?我之前用过一个相似的例子,没有问题?

更多咖啡...

+0

也许试用'.... ACTION =“/ card.pl”'。另外password.pl缺少标题部分。 – zindel 2011-04-05 11:56:08

+2

heredoc对于输出HTML更具可读性 – 2011-04-05 14:25:57

use strict;use warnings;看看自己的错误日志。还有validate你的HTML。

然后你会被警告类似的原因:

裸词“通行证”时不允许使用“严格潜艇”在使用中card.pl线7

你可能想:

($password eq 'pass') 
+0

感谢您的提示,学到很多东西,时间不多。 – mrlayance 2011-04-05 12:08:27

在我不断寻求打消CGI.pm的滥用,你的第一个脚本将原样

好得多
use strict; 
use warnings; 
use CGI qw(:standard); 

print 
    header(), 
    start_html("O HAI CARD"), 
    start_form(-action => "card.pl"), 
    fieldset(
      legend("None Shall Pass!"), 
      password_field(-name => "password", 
          -size => 25), 
      submit(-value => "Submit"), 
      ), 
    end_form(), 
    end_html(); 

你的第二个作为,也许,只是举例,等cetera-

use strict; 
use warnings; 
use CGI; 
my $q = CGI->new; 

print 
    $q->header, 
    $q->start_html("O HAI CARD"); 

my $password = $q->param("password"); 

if ($password eq "pass") 
{ 
    print $q->h2("You're all good"); 
} 
else 
{ 
    print $q->h2({-style => "color:#a00"}, 
      "You're all good"); 
} 

print $q->end_html(); 

或者,也许更好,所有比比看

use strict; 
use warnings; 
no warnings "uninitialized"; 
use CGI qw(:standard); 

print 
    header(), 
    start_html("O HAI CARD"); 

print param("password") eq "pass" ? 
    h2("Yes!") : h2({-style => "color:#a00"}, ":("); 

print 
    start_form(), 
    fieldset(
      legend("None Shall Pass!"), 
      password_field(-name => "password", 
          -size => 25), 
      submit(-value => "Submit"), 
      ), 
    end_form(), 
    end_html(); 

RIF,阅读文档:CGI