Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

RE: Quick and easy way to prevent multiple votes?

by Anonymous Monk
on Jun 08, 2000 at 19:09 UTC ( [id://17093] : note . print w/replies, xml ) Need Help??

in reply to Quick and easy way to prevent multiple votes?

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.