HomePHP Page 2 - Creating a Fraud-proof Voting System
One Person, Multiple Addresses, Still One Vote - PHP
Setting up polls or voting systems is a great way to get users more involved in your website, and keep them coming back for more. But with fraud hanging over the professional political elections, how do you keep your visitors from screaming for a recount--or worse, stuffing the ballot box? Ian Felton describes a simple system for setting up an online poll and preventing abuses.
Sending the email is only the first step for fraud prevention because some people have a thousand email addresses. Someone could (and would) vote for the same song using all of their email addresses and skew the results in that way. Because of situations like that, the system also needs to verify that fans aren稚 using multiple email addresses. The verification email also needs some sort of key so that the verification script cannot be easily hacked.
Two scripts comprise the bulk of the system. One script, vote.php, casts the vote and sends the verification email. Another script, verify.php sets the vote as valid after Dick clicks the link in his inbox. A table in the database will need to be created to store votes.
First, we値l setup the table in the database to store the votes that are cast. We need a basic primary key called ID. We値l store the email address of the voter. We値l timestamp the vote. We need a column that shows whether the vote has been verified. It will be a Boolean flag. We値l store the ID of the band receiving the vote. We値l store the song name and finally the IP address of the voter.
CREATE TABLE `votes` ( `ID` int(10) unsigned NOT NULL auto_increment, `email` varchar(255) NOT NULL default '0', `time` timestamp(14) NOT NULL, `pending` tinyint(1) unsigned NOT NULL default '0', `bandID` int(10) unsigned NOT NULL default '0', `song` varchar(255) default NULL, `IP` varchar(15) NOT NULL default '0', PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`), KEY `ID_2` (`ID`) ) TYPE=MyISAM AUTO_INCREMENT=0;