What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

Could I make this voting system with PHP?


Junior Member
I want to make a voting system that look a little something like this:
Each user gets 10 votes a day they use to vote for various people.
Every 24 hours it gets refilled up to 10 again.
Users dont need to register to vote, I just want to let different IP address vote
A top 5 list of people that were voted on the most that updates every 24 hours.
I also want to have a top 5 list of the week, month, and all time
A line graph of each person's point fluctuation over time (just like companies stock price) in their profiles.

I was thinking I could do the top 5 list with arrays & for loops or something, but I got no idea how to detect IP addresses & let people vote. Would it be easy to make something like this w/ PHP?
You'll probably want to use a database (MySQL) to keep track of things, too, anything that needs to be stored for any length of time. If you want to show real-time votes, then you'll want to look into Javascript and employ some AJAX techniques. You could definitely do this with PHP, just keep in mind there's other stuff you'll need, too.
Yeah you will definitely need a database. Depending on how you set it up, you might want IP addresses to one table and votes to the other. You could set a field in both tabled which would match with the IP table, and based on the query you used, you can determine how many times a user has voted and decide weather or not to add the vote to the votes column.

I hope this is helpful in your development of this project.
The front-end would be a piece of cake to do with PHP. The back-end should be database driven. Two options for the votes tracking thing, either keep a tally on the user table (or whereever you will store your user's vital data, I always call it a user table) that gets incremented every time a vote is used, then run a job every night that resets these values to 0 (less resource intensive overall I think) or you could just do a query on how many votes for that user have been added to some sort of voting table, and not allow more when there are at least ten (this is a little more resource intensive). You might be able to build in a database constraint, but communicating that to the front end might get tricky.

Of course, you could also have a mix of both, have a flag on the user table that says whether you can vote or not, and have a job that runs constantly that queries the voting table for all users can sees if they have more than ten votes, updating their flag if they do. Downside to this is that it is much more resource intensive and would allow users to quickly cast as many votes as possible before the script can run (basically, makes you vulnerable to bots).
Yes. PHP is ideal for such a project. I can't think of anything else you could use for such a web app, to be honest.