hacker has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to incoporate the ability to have a voting booth style "slashbox"/"nodelet" on the website. I've written smaller ones before, but this one will be getting substantially more hits, and I'll want to be using GD/jpgraph (or similar technologies) to graph the results.
The interesting question becomes, what is a really good way to make sure the ballots aren't "stuffed" in the voting mechanism. I have seen several ideas in the past, which all have good and bad points:
Has anyone implemented a solution that doesn't suffer from stuffed ballots, race attacks, locking conditions (mysql-based storage would solve the last two), etc.? I've personally used file-level storage of the bits, but never done any voting mechanisms using mysql as a storage mechanism.
Implementing the perl around it is no problem for me, unless it's really unusual structures. Modules in this space? CPAN didn't bring up much.
Here's some sample code from one I wrote about 5 years ago. It suffers from many problems if implemented now:
...and so on. This particular one is subject to race attacks, but I tried to use a cookie-based approach at the time to stop ballot stuffing. This is no longer a viable approach, since many of the European visitors keep cookies and Javascript disabled, for reasons of security.########################################### # Grab the user's vote and store it in the # appropriate file. If the file does not # exist it will be created on the fly. ########################################### sub record_vote { if ($cookie_state != 1) { $votes_file = "vote/platform/$poll"; open (VOTES, "$votes_file"); while (<VOTES>) { $count1 = $_; } close VOTES; $count1 += 1; open (VOTES, ">$votes_file"); print VOTES $count1; close VOTES; } } ########################################## # Calculate the vote totals ########################################## sub calculate_vote { opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @vote_dir_files = grep { !/^\./ && -f "$some_dir/$_" } readdir(DIR) +; closedir DIR; foreach $fred (@vote_dir_files) { open FILE, "$some_dir/$fred" or die; while (<FILE>) { $value = $_; } close FILE; $files{$fred} = $value; $totals = ($totals + $value); } } ########################################## # Display the vote results and the chart # with varying widths for the percentage # of votes ########################################## sub results { my $vote_width = 0; $table_width = "440"; $table_remaining = ($table_width - 110); $vote_status = "(<b>You've already voted for $cookie_value</b>)" if ($cookie_state == '1'); # Lots of HTML here to "pretty-up" the displayed # output, removed for this SoPW post for $key (sort { $files{$b} <=> $files{$a} } keys %files) { $vwm = ($table_remaining/$files{$key}) unless $vwm; $vote_width = ($files{$key}); my $percentage_width = ($files{$key}/$vwm); my $unrounded_vote_percent = ($files{$key}/$totals)*100; my $rounded_vote_percent = sprintf("%.2f", $unrounded_vote_percent) +; my $blank_cell = (($files{$key})*$vwm);
Is there anyother series of approaches that might work for this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: "Session Tracking" Voting Booth CGI
by Ryszard (Priest) on Jun 03, 2002 at 12:47 UTC | |
by hacker (Priest) on Jun 03, 2002 at 13:41 UTC | |
by Ryszard (Priest) on Jun 03, 2002 at 14:46 UTC | |
|
Re: "Session Tracking" Voting Booth CGI
by dwiz (Pilgrim) on Jun 03, 2002 at 11:13 UTC | |
|
Re: "Session Tracking" Voting Booth CGI
by Aristotle (Chancellor) on Jun 03, 2002 at 22:17 UTC |