Jump to content

Vote once


Graxeon

Recommended Posts

I'm not a real PHP guru but I can't grasp the idea of how to have a poll and make a cookie that will disable users from voting for a certain amount of time.

 

Here's a voting script that I found very useful:

 

http://www.w3schools.com/php/php_ajax_poll.asp

 

But just by refreshing the page I can vote again. I tried googling "how to save a cookie" and this is what I came up with:

 

http://blazonry.com/javascript/cookies_save.php

 

But I don't know how to combine those 2 scripts.

 

Any help?

 

 

Edit:

 

Oh I also did search on these forums and found a few posts with the same problem...but they were from people that didn't speak newbie xD

Link to comment
https://forums.phpfreaks.com/topic/170290-vote-once/
Share on other sites

Well...for ip logging I found this but I still need help combing the 2:

 

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$pagina = $_SERVER['REQUEST_URI'];
$datum = date("d-m-y / H:i:s");
$invoegen = $datum . " - " . $ip . " - " . $pagina . "<br />";
$fopen = fopen("ips.html", "a");
fwrite($fopen, $invoegen);
fclose($fopen);
?>

Link to comment
https://forums.phpfreaks.com/topic/170290-vote-once/#findComment-899554
Share on other sites

Moved.

 

In short:

 

 

 

when user votes, check the database if that user has voted.

    if he hasnt

        Store the IP and time of vote in the database.

    if he has

        get the time of his last vote and the current time to do your time-span calculation

                if X time has passed

                    He can vote. register his vote and update database so time of his last vote is the current time

 

 

If you want to implement cookies, you can fit that in there as well. but like i said, very easy to bypass

Link to comment
https://forums.phpfreaks.com/topic/170290-vote-once/#findComment-900077
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.