LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1331|回复: 4

LOGIN。CGI为什么老是显示“登陆失败”?谢谢~

[复制链接]
发表于 2004-4-14 21:25:12 | 显示全部楼层 |阅读模式
#!/usr/bin/perl

#reg.cgi
print "Content-Type: text/html\n\n";


read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});

@userpassword=split(/&/,$buffer);

foreach $namevalue(@userpassword){

($name,$value)=split(/=/,$namevalue);

$name=~tr/+//;
$value=~s/%[\da-fA-F][\da-fA-F]/pack("C",hex($1))/eg;

$form{$name}=$value;
}

$username=$form{'username'};

$password=$form{'password'};

$pass_word=$form{'pass_word'};

$db="F:/user/shoufei/yuliner/testtest/data/$username.pl";

open(FILE,">$db")||die"can not open $db";

print FILE "\$username = \'$username\'\;\n";

print FILE "\$password = \'$password\'\;\n";

print FILE "1;";

close(FILE);

print "<html><head><title></title></head><body>注册成功!</body></html>";

exit;







login.htm



<html>
<head>
<title></title>
</head>
<body>

<form action="login.cgi" method="post">
<p>username:<input name="username" type="text" size="20" maxlength="20"></p>
<p>password:<input name="password" type="password" size="20" maxlength="20"></p>
<p>password:<input name="pass_word" type="password" size="20" maxlength="20"></p>
<p align="center"><input type=submit name=submit value=" 登  录 ">
<p align="center"><a href=reg.htm>注册</a>
</form>

</body>
</html>





#!/usr/bin/perl
#login.cgi

print "Content-type:text/html\n\n";

read(STDIN,$buffer,$ENV{'CONTENT-LENGHT'});

@pairs=split(/&/,$buffer);

foreach $keyvalue(@pairs){

   ($key,$value)=split(/=/,$keyvalue);

$value=~tr/+//;
$value=~s/%[\da-fA-F][\da-fA-F]/pack("C",hex($1))/eg;

$form{$key}=$value;

}

$user=$form{'username'};

$pws=$form{'password'};

$pw=$form{'pass_word'};

$userdb="F:/user/shoufei/yuliner/testtest/data/$user.pl";

if  (-e  "$userdb" ){


   require "$userdb";

       if  ($pws eq $password){


              print "<html><head><title></title></head><body>成功登陆!</body></html>";


     }

}
else{

print "<html><head><title></title></head><body>登陆失败!</body></html>"; }

exit;











请大家帮忙看看,谢谢~
发表于 2004-4-15 02:07:48 | 显示全部楼层

不知道可以換個方式嗎?

我也是初學者

#!/usr/bin/perl

## 文件檔案index.pl
use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';
use strict;

my $name  = cookie('sessionID') || 'geust';
my $space = '&nbsp' x 9;

print   header(-charset=>'big5',-expires=>'-1d'),
        start_html(-title=>'Welcome to My Page',
                 -lang=>'big5',
                 -encoding=>'big5');

print   h2({-align=>'center'},'Create new account'),
        h2("Hi$space$name"),hr,

        start_form(-action=>'create.pl',-method=>'post'),
       
        '帳號',br,br,
        textfield(-name=>'user',
                  -override=>'1',
                  -size=>'20',
                  -maxlength=>'40'),br,br,
        '密碼',br,br,
        password_field(-name=>'password',
                       -override=>'1',
                       -size=>'21',
                       -maxlength=>'40'),br,br,
        submit('傳送'),
        end_form,
        end_html;

........................完

#!/usr/bin/perl

## 文件檔案 create.pl

use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';
use strict;

my $user     = param('user');
my $password = param('password');
my $space    = '&nbsp' x 9;
my $cookie   = cookie( -name=>'sessionID',
                       -value=>"$user",
                       -expires=>'+1y');
                       
print redirect('index.pl') unless ($user && $password);

print header(-charset=>'big5',
             -cookie=>$cookie),
      start_html(-title=>'Create new account',
                 -lang=>'big5',
                 -encoding=>'big5');

print   "以下是妳申請的資料",hr,br,br,
        "帳號",$space,$user,br,
        "密碼",$space,$password,br,br,
        a({href=>'index.pl'},'回主頁')

........................完
 楼主| 发表于 2004-4-15 09:17:20 | 显示全部楼层
呵呵,我也看不懂..
发表于 2004-4-15 09:19:09 | 显示全部楼层
print FILE "\$username = '$username'\;\n";

print FILE "\$password = '$password'\;\n";
单引号和双引号的区别
 楼主| 发表于 2004-4-15 21:23:00 | 显示全部楼层
print FILE "\$username =\'$username'\;\n";

print FILE "\$password = \'$password'\;\n";
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表