2011-04-05 85 views
2

我想從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

回答

8

use strict;use warnings;看看自己的錯誤日誌。還有validate你的HTML。

然後你會被警告類似的原因:

裸詞「通行證」時不允許使用「嚴格潛艇」在使用中card.pl線7

你可能想:

($password eq 'pass') 
+0

感謝您的提示,學到很多東西,時間不多。 – mrlayance 2011-04-05 12:08:27

1

在我不斷尋求打消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

相關問題