Allowing only one vote per person on a voting system

Shawn31313 picture Shawn31313 · Jul 30, 2012 · Viewed 8.3k times · Source

I'm working on a little posting system so I can post posts on my site and people can like and dislike it.

It looks like this:

the voting system

At the moment you can upvote and downvote as many times as you would like. I know how to make the images not clickable with JavaScript but I also need a way to do this in PHP because someone could just make the buttons clickable again with fireBug or the Chrome Console.

This is probable the first thing i'm actually making in PHP so i'm still a beginner. Thanks for any suggestions.

Answer

Tim Withers picture Tim Withers · Jul 30, 2012

I am not going to just write code for you, and there are probably dozens of workable examples on script sites. Here are a few tips to get you pointed in the right direction:

Session variables - $_SESSION[] - Check if it is set, and then set them after a vote. As long as they don't close the browser, they won't be able to vote again.

Cookies - $_COOKIE[] - Same as session, but can remain even if they close and open their browser again.

IP Address - $_SERVER['REMOTE_ADDR'] - Keep a record in a MySQL table of IPs and votes.

Login system - Only allow authenticated users to vote, and then keep track of the votes in the database.

Any combination of the above is acceptable. Hope that gets you pointed in the right direction.