in reply to Re: Checking for cookies
in thread Checking for cookies
#!/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.~;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Checking for cookies
by rpanman (Scribe) on Jul 13, 2007 at 06:20 UTC | |
by Eagle_f90 (Acolyte) on Jul 15, 2007 at 04:16 UTC |