in reply to Checking for cookies

You know how to pull a value from a cookie, so do that first. If the routine you use to get the value of the cookie does not work then it is likely that the cookie is not set...

If you post some code then it should be easy to show you how to do this.

Replies are listed 'Best First'.
Re^2: Checking for cookies
by Eagle_f90 (Acolyte) on Jul 13, 2007 at 02:41 UTC
    Tried adding an if statment to check value but am still erroring out with "Can't call method "value" on an undefined value at vote.pl line 14." line 14 is the if statment.
    #!/user/perl use CGI q~:standard~; use CGI::Cookie; use CGI::Carp qw(fatalsToBrowser); use strict; use DBI; print "Content-type: text/html\n\n"; my ($dbh, $sth, $filename, $rating, @current, @VotedOn, %cookies, $Can +Vote, $value, $c); $filename = param('name'); $rating = param('rating'); %cookies = fetch CGI::Cookie; $CanVote = 1; @VotedOn = ''; if ($cookies{'FFInfoVotedOn'} -> value) { @VotedOn = $cookies{'FFInfoVotedOn'} -> value; foreach $value (@VotedOn) { if ($value eq $filename) { $CanVote = 0; } } } if ($CanVote) { $dbh = DBI -> connect ('dbi:ODBC:FFmisc', '', '') or die $DBI::err +str; $sth = $dbh -> prepare (qq~select One, Two, Three, Four, Five from + FanRatings where Title = ?~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; @current = $sth -> fetchrow_array; if (!defined $current[0]) { $sth -> $dbh -> prepare (qq~insert FanRatings (Title, One, Two +, Three, Four, Five) values (?, 0, 0, 0, 0, 0)~) or die $DBI::errstr; $sth -> execute ($filename) or die $DBI::errstr; } $sth = $dbh -> prepare (qq~update FanRatings set ? = ? + 1 where T +itle = ?~) or die $DBI::errstr; $sth -> execute ($rating, $rating, $filename) or die $DBI::errstr; @VotedOn = (@VotedOn, $filename); $c = new CGI::Cookie(-name => 'FFInfoVotedOn', -value => @VotedOn, -expires => '+10Y', ); print header(-cookie => $c); print qq~Thank you for rating this fan creation.~; } else { print qq~I am sorry but you have alrady rated this fan creation.~; } print qq~<br />You will automaticly be taken back to the page you came + from in 5 seconds.~;
      Okay, a bit easier to help with the code now. It is probably best to check that the cookie exists before trying to call a method on it (you are getting the error because the cookie does not exist and so perl cannot find relevant "value" method).

      Try this:
      if (exists($cookies{'FFInfoVotedOn'})) {
        Thanks I always forget about the "exists" command