<?php echo "Which is your favourite film?<br><form action='' method='post'>\n";
$query = mysql_query("SELECT movie, movieid, votes FROM moviepoll ORDER BY movieid");
while ($result = mysql_fetch_assoc($query))
{
echo "<input type='radio' name='box' id='box", $result["movieid"], "' value='", $result["movie"], "'>";
echo "<label for='box", $result["movieid"], "'>", $result["movie"], "</label> (currently has ", $result["votes"], " votes) <br>\n";
}
echo "<input type='submit'>\n</form>";
$movie = $_POST["box"];
if(isset($movie))
{
$expire = time() +30;
if(isset($_COOKIE["voted"]))
{
echo "Sorry, you've voted already";
}
else
{
$query = mysql_query("SELECT movie, movieid FROM moviepoll WHERE movie='$movie'");
$result = mysql_fetch_assoc($query);
$id = $result["movieid"];
$name = $result["movie"];
$sql = "INSERT INTO moviepoll (movieid, movie) VALUES ($id, '$name') ON DUPLICATE KEY UPDATE votes = votes + 1";
mysql_query($sql);
if(time() > $expire)
{
setcookie("voted", $name, time()-30);
}
setcookie("voted", $name, $expire);
}
}
?> and am trying to use cookies to limit the user voting again for a while, but I can't seem to get the cookies worked out, can you help?Cookie Trouble
-
wrichards8
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Cookie Trouble
I have this poll code
Re: Cookie Trouble
It looks like it would work to me (although a huge mess !), what is the problem exactly ?
-
wrichards8
- Posts: 66
- Joined: Thu Jan 12, 2012 3:54 pm
- Contact:
Re: Cookie Trouble
It might just be my browser, but the cookie doesn't seem to expire and unset itself properly.
Re: Cookie Trouble
if(time() > $expire)
{
setcookie("voted", $name, time()-30);
}
setcookie("voted", $name, $expire);
ah, here you are unsetting the ciikie and then imediately setting it again.