Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Thank you for all your interesting ideas and suggestions. The code I have copy with now is
sub already_voted { my ($ip_address, $user_agent) = @_; my (@lines, $line, $file_ip, $file_ua, %voters, $voted); # Open our list of IP address and user agents. # This is in the format: # # IP_address:::UserAgent # open (IPADDRESS, "<ips.txt"); @lines = <IPADDRESS>; close IPADDRESS; # Parse the array and store IP and User Agent in a hash. foreach $line (@lines) { chomp $line; # Remove \n ($file_ip, $file_ua) = split(/:::/, $line); $voters{$file_ip} = $file_ua; } # Check to see if the IP of the person currently voting # is in the hash. if (exists($voters{$ip_address})) { # It looks like the same person is voting again. Stop the # evil person. But wait, let's check the user agents too. if ($voters{$ip_address} eq $user_agent) { # Same IP, same user-agent. Looks like a duplicate vote. $voted = 1; sharedcode::logfile("Bad: dup vote $ip_address and $user_agent." +);. } } # Let's put *this* vote into the file: open (IPFILE, ">>ips.txt"); print IPFILE "$ip_address".':::'."$user_agent\n"; close IPFILE; if ((-M "ips.txt") >= 7) { # File is getting old, let's clear the file. open IPFILE, ">ips.txt"; print IPFILE " "; close IPFILE; } return $voted; }
Obviously, this code isn't going to trap 100% of the cheaters, but that's fine by me. Thanks again for all your suggestions.

In reply to RE: Quick and easy way to prevent multiple votes? by Anonymous Monk
in thread Quick and easy way to prevent multiple votes? by Anonymous Monk

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.