perl - Cookie error when using CGI::Session -


it's first experiment cgi::sessions , i'm getting error message in logs don't know how fix. looks problem on line 28 of code, $cookie variable in not imported:

[mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] variable "$cookie" not imported @ /usr/lib/cgi-bin/login.pl line 28. 5028 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] \t(did mean &cookie instead?) 5029 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] variable "$cookie" not imported @ /usr/lib/cgi-bin/login.pl line 29. 5030 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] \t(did mean &cookie instead?) 5031 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] global symbol "$cookie" requires explicit package name @ /usr/lib/cgi-bin/login.pl line 28. 5032 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] global symbol "$cookie" requires explicit package name @ /usr/lib/cgi-bin/login.pl line 29. 5033 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] bareword "username" not allowed while "strict subs" in use @ /usr/lib/cgi-bin/login.pl line 34. 5034 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] bareword "password" not allowed while "strict subs" in use @ /usr/lib/cgi-bin/login.pl line 35. 5035 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] execution of /usr/lib/cgi-bin/login.pl aborted due compilation errors. 5036 [mon aug 18 21:42:32 2014] [error] [client 127.0.0.1] premature end of script headers: login.pl

here's code:

1 #!/usr/bin/perl -wt   2 use strict;   3    4 use cgi::session;   5 use cgi qw(:standard);   6    7 %names = map { $_ => 1 } param;   8 $open = "1234";   9   10 sub windowlayout() {  11           header,  12           start_html("input form"),  13           start_form,  14           "please enter username:",  15           textfield(-name=>'username',  16                           -maxlength=>20),p,  17           "please enter password:",  18           password_field(-name=>'password',  19                           -maxlength=>20),p,  20           submit,hr  21 }  22   23 if ($names{username} , $names{password}) {  24   25 $cgi = new cgi;  26 $session = new cgi::session(undef, $cgi, {directory=>'/tmp'});  27   28 $cookie = $cgi->cookie(cgisessid => $session->id);  29 print $cgi->header(-cookie=>$cookie);  30   31 $username  = param("username");  32 $password  = param("password");  33   34 $session->param(username, $username);  35 $session->param(password, $password);  36   37  if ($password ne $open) {  38        print  39         windowlayout(),  40         end_form,  41           p({-style=>'color: red;'},  42                  "sorry wrong password!");  43        print end_html;  44   } else {  45        print  46           redirect("hello.pl");  47   }  48  }else {  49     print  50          windowlayout(),  51          end_html;  52  }    

as you're using strict in code (which is, of course, great habit in to), you'll need declare of variables my (or equivalent). don't $cookie.

so change:

$cookie = $cgi->cookie(cgisessid => $session->id); 

to:

my $cookie = $cgi->cookie(cgisessid => $session->id); 

for future reference, if perl error message don't understand, can more detail problem adding use diagnostics code (but remember remove again once problem fixed).

you have couple of other errors. strings 'username' , 'password' need quoted string on lines 34 , 35.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -