2

I am having a html file which will accept and send the login and password. It is sent to the file login.cgi.

**

  • html file

**

<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
  }

After starting the apache server, i open the page and enter the username as demo and password as demo and click on the button.

I get the following error:

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.

Please help me out to resolve this error.

**

  • EDIT 1

**

Problem resolved after installing CGI-Session-4.42.

Thanks to all of you, for your help.

MalarN
  • 315
  • 3
  • 7
  • 20
  • 4
    Obviously you haven't CGI::Session installed. Try `cpan` from the command line and run `install CGI::Session` in the opening shell... – Boldewyn Feb 08 '10 at 09:51
  • I tried to install cpan, but every where the connection does not happen. Also, i am getting the following at the end : Could not fetch modules/03modlist.data.gz Going to write /root/.cpan/Metadata Warning: Cannot install Bundle::CPAN, don't know what it is. Try the command i /Bundle::CPAN/ to find objects with matching identifiers. cpan> i /Bundle::CPAN/ No objects found of any type for argument /Bundle::CPAN/ cpan> /Bundle::CPAN/ Can't locate object method "CPAN/" via package "/Bundle" (perhaps you forgot to load "/Bundle"?) at /usr/lib/perl5/5.8.8/CPAN.pm line 201, line 3. – MalarN Feb 08 '10 at 10:41

1 Answers1

11

You need to install CGI::Session. Best way is to use your OS package manager. In Fedora/Redhat or similar it would be yum install perl-CGI-Session. In Debian-based, apt-get install libcgi-session-perl. If you want to install with cpan shell, paste somewhere whole log with errors and publish link to it here.

Alexandr Ciornii
  • 7,346
  • 1
  • 25
  • 29
  • I tried to install through "yum" but getting the following error: [root@localhost /]# yum install perl-CGI-Session Loading "installonlyn" plugin Setting up Install Process Setting up repositories Could not retrieve mirrorlist http://mirrors.fedoraproject.org/mirrorlist?repo=core-6&arch=i386 error was [Errno 4] IOError: Error: Cannot find a valid baseurl for repo: core – MalarN Feb 08 '10 at 11:16
  • The key part looks to be "IOError: ". Are you sure that the machine you're attempting this on has working internet access? – Dave Sherohman Feb 08 '10 at 11:30
  • Try simple `ping mirrors.fedoraproject.org`. – Alexandr Ciornii Feb 08 '10 at 15:57
  • Do you have a firewall? It sounds like you could either have a firewall/proxy issue or a internal server DNS issue. – Weegee Feb 08 '10 at 17:37
  • @Alexandr Ciornii: ping is not responding. What can be done, please help me out. – MalarN Feb 09 '10 at 04:18
  • @Weegee: Please help me in resolving the firewall/proxy issue? – MalarN Feb 09 '10 at 04:19
  • you just saved my day! nowhere else could i read libcgi-session-perl was required, and this was actually the key. – Couitchy Jun 04 '19 at 12:45