I have a website where we are collecting votes for something. I want to use cookies to deter people from re-voting (yes, this is not efficient if they're smart enough to turn their cookies off). I seem to have successfully created a cookie, and then code to read that cookie and redirect. However, it places the cookie before looking for the cookie, so it immediately redirects, rather than redirecting on the next visit.
Can I either:
a) set the cookie to be installed in a few moments (or after the page loads - with the reading script being run immediately as the page loads)
b) set the cookie to be placed on page exit
c) set the cookie to be placed on the submit button for the form for voting?
Thanks for any help.
C.
Here's the code I'm using, in this order, at the very top of the page after the first <?... setting:
Expand|Select|Wrap|Line Numbers
- if (!isset($_COOKIE['voted']) || $_COOKIE['voted'] != "voted") {
- header ("Location: ../thanks-for-voting.php");
- }
- setcookie("voted", "voted", time()+86400*10);