Good morning, fellow monks. I have a question that is more of a design question, one of many to follow this week as I wrap up some more code on my new dynamic website for Plucker. This one concerns a Voting Booth:

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:

########################################### # 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);
...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.

Is there anyother series of approaches that might work for this?


In reply to "Session Tracking" Voting Booth CGI by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.