perl - 为什么我的 CGI 脚本提示 "Can' t locate CGI/Session.p

我有一个 html 文件,它将接受并发送登录名和密码。它被发送到文件 login.cgi。

**

  • html 文件

**

<form method="POST" action="login.pl">
<table >
<tr>
    <td>Username </td>
    <td bgcolor="lightgrey"><input type="text" name="usr" size="20"></td>
</tr>
<tr>
    <td>Password </td> 
    <td bgcolor="lightgrey"><input type="password" name="pwd" size="20"></td>
</tr>
<tr>
    <td><input type="submit" id ="Login" value="Login" name="login"/> </td>
</tr>
</table>

**

  • .pl

**

#!/usr/bin/perl

  # login.pl
  use CGI;
  use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
  use CGI::Session ( '-ip_match' );

  $q = new CGI;

  $usr = $q->param('usr');
  $pwd = $q->param('pwd');

  if($usr ne '')
  {
      # process the form
      if($usr eq "demo" and $pwd eq "demo")
      {
          $session = new CGI::Session();
          print $session->header(-location=>'home.html');
      }
      else
      {
          print $q->header(-type=>"text/html",-location=>"LoginHtml.html");
      }
  }
  elsif($q->param('action') eq 'logout')
  {
      $session = CGI::Session->load() or die CGI::Session->errstr;
      $session->delete();
      print $session->header(-location=>'LoginHtml.html');
  }
  else
  {
      print $q->header;
      print <
          <form method="post">
          Username: <input type="text" name="usr">

          Password: <input type="password" name="pwd">


          <input type="submit">
          </form>
  HTML
  }

启动apache服务器后,我打开页面,输入用户名demo和密码demo,然后点击按钮。

我收到以下错误:

Software error:

Can't locate CGI/Session.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl/5.8.7 /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl/5.8.7 /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /var/www/cgi-bin/login.pl line 6. BEGIN failed--compilation aborted at /var/www/cgi-bin/login.pl line 6.

For help, please send mail to the webmaster (root@localhost), giving this error message and the time and date of the error.

请帮我解决这个错误。

**

  • 编辑 1

**

安装 CGI-Session-4.42 后问题解决。

感谢大家的帮助。

相关文章:

objective-c - 如何使用可为空的 int 或 NSInteger 指针?

regex - 带数字的 CSV 正则表达式

vb.net - 如何从消息框中获取结果?

.net - 来自非托管代码的 System.AccessViolationException?

ios-simulator - class_getClassMethod 通常返回 nil(似乎只适

python - 获取当前日期作为方法的默认参数

php - 不同 php 版本上的不同 sha1 校验和?

bash - 将 bash 中的逗号分隔数据包装成固定的行长度

php - 使用php过滤掉数组中的重复值

delphi - 用Delphi如何获取当前安装的IE版本?