|
homegrown perl developer usually on linux, but this is on windows box, but not sure that matters....
i get:
Can't call method "cookie" on an undefined value at \cgi-bin\article_admin.pl line 11.
error when trying to retrieve cookie value (for a cookie of name 'articles' that i set on a previous page) via CGI in order to test whether user should have access to this page. the relevant code snippet is below. not sure why it would have an undefined value? can anyone help, as i'm undoubtedly just being stupid but am working alone right now and very stuck. thanks.
1#!/usr/bin/perl -w
2
3 use strict;
4
5 use CGI;
6 use CGI::Carp qw(fatalsToBrowser);
7
8 my $query = new CGI;
9 my $cgi;
10 my $cookie_exists ="no";
11 $cookie_exists = $cgi->cookie('articles');
|
|
|
#!/usr/bin/perl -Tw
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $query = new CGI;
# my $cgi; # Dont need this
my $cookie_exists = $query->cookie('articles'); # Use $query a defined value and the one in this code that will use CGI.pm to get the cookie
if(!$cookie_exists) { $cookie_exists = 'no'; }
This was your main problem $cgi->cookie('articles'); becase you called my $query = new CGI; the get cookie will need to use $query->cookie('articles'); and my $cgi; is not needed.
|
|
|
|
|
|
|
|