How can i set a time that a person can vote again?

175 views Asked by At

i have a voting system that you dont have to login to and i want to know how i can set it to where they can vote once per day, either by blocking IP or something of the sort. i prefer not to have a database

<script type="text/javascript">

var clicks = 0;
function linkClick(){
document.getElementById('clicked').value = ++clicks;
}

document.write('<a href="#" onclick="linkClick()">Vote Now!</a>');

$('#clicked').parent().bind('click', function(evt) {
$(this).unbind('click');   
/* do long time task....

evt.preventDefault();
});


</script>

You have clicked the link <input id="clicked" size="3" onfocus="this.blur();" value="0" > times

this code as it stands will only let a use vote once and only once, i would like it to be every 24 hours and in html, thank you in advance

2

There are 2 answers

2
Roloc On BEST ANSWER

You could create a cookie and check that each day to see if they have voted already. Although JCO611 is correct, this is easily bypassed. I would recommend using some server side code.

For more on cookies in javascript: http://www.quirksmode.org/js/cookies.html

2
Pan Thomakos On

It's not possible to implement this in a safe way in javascript or HTML. The reason is that as a web-user I can clear my cookies, open a new browser, or make calls to your server programatically without having to use your user interface. This means you need something on the server to prevent me from actually submitting twice within a day, regardless of what the web-page looks like.

My recommendation would be to use a user-login to verify that the user hasn't posted twice.