Page 1 of 1

Only allow 3 votes a week

Posted: Wed Nov 25, 2009 10:25 pm
by xionhack
Hello. I have a form, where you can vote for different songs. What I want is for you to only be allowed to vote 3 times a week, the voting system being reset every monday at 12:01 am. How can I do that? Thanks!

Re: Only allow 3 votes a week

Posted: Thu Nov 26, 2009 3:49 am
by Grizzzzzzzzzz
You could use cookies, but they can easily be got around by deleting them.

You could use I.P tracking with a SQL database, which is slightly better, but people could still get around it.

Probably the best way is to only allow people to vote if they have a registered account with a unique verified email. But that limits your voting base and excludes people that don't want to bother signing up.




It depends what you're using it for. If its simply a school project and integrity isn't taken into account, use cookies. If it's for a larger project, i'd personally use an I.P tracking system as it would be good enough. If the votes really matter and you don't want one person getting around your system and voting multiple times, use a registration system, or even a combination of all 3.

Re: Only allow 3 votes a week

Posted: Thu Nov 26, 2009 11:35 am
by xionhack
Yes, Im sorry I didnt explain better. They have to be registered to vote. I have a table where I record the votes, who did it, and when was done. My problem is how to know when you've already voted 3 times this week.

Re: Only allow 3 votes a week

Posted: Thu Nov 26, 2009 12:03 pm
by Grizzzzzzzzzz
have another table in the db with their username, and their votes

then where the voting takes place, do an SQL statement like this

Code: Select all

 
$query= "SELECT * FROM votes WHERE name = '$name'";
$result=mysql_query($query);
$rows = mysql_num_rows($result);
 
if ($rows >= 3)
{
     //don't allow vote
}
else
{
    //do allow vote
}
 
 

then at the start of the new week you could run a php script that'll drop all the contents of the table, allowing them to start fresh.

or you could also store the week number using the php date function to do it automatically for you if its a new week.

Re: Only allow 3 votes a week

Posted: Thu Nov 26, 2009 12:06 pm
by xionhack
What if I want the week to start on monday 12:01 am and ending on sunday at 12:00

Re: Only allow 3 votes a week

Posted: Thu Nov 26, 2009 12:14 pm
by Grizzzzzzzzzz
Then make it so it does, that link i gave you shows you to store those date in exactly that format

check the day of the week would be using

Code: Select all

 
$day = date("l");
 
check if its past a certain time would be using

Code: Select all

 
$time = date("Hi");
 
etc..

Re: Only allow 3 votes a week

Posted: Thu Nov 26, 2009 12:57 pm
by daedalus__
record their username and a timestamp with their vote

then create a query that says

"select blah from votes where date is older than now() but newer than 12:01am last monday"

you could figure out the day of the week sort of like this:

Code: Select all

 
$day_of_the_week = date('N', time());
 
$last_monday = mktime(0, 0, 0, date('n', time()), date('j', time()) - ($day_of_the_week - 1), date('Y', time()));
 
i didn't test that code to make sure it works but the idea is to take the iso 8601 day of the week and count your way back to last monday