Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

RE: Quick and easy way to prevent multiple votes?

by BigJoe (Curate)
on Jun 08, 2000 at 04:04 UTC ( [id://16994] : note . print w/replies, xml ) Need Help??


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

try something like
open(INFILE, "< listofips.txt"); $filesize= -s INFILE; read(INFILE, $wholepage, $filesize); close(INFILE); if( !($wholepage =~ m/$ENV{'REMOTE_ADDR'}/) ) { open(OUTFILE, ">listofips.txt"); print OUTFILE "$wholepage\n"; print OUTFILE $ENV{'REMOTE_ADDR'}; close(OUTFILE); # add vote stuff here }
This should be kinda what you are looking for. I think there is a simpler way. I just don't know it yet.

Replies are listed 'Best First'.
RE: RE: Quick and easy way to prevent multiple votes?
by chromatic (Archbishop) on Jun 09, 2000 at 03:00 UTC
    Yeah, there are simpler ways to keep a list of IPs. As the list grows, time to check them increases tremendously.

    If you really must do it this way, use a database. Even something simple like DBD::CSV would help immensely.

    Specific things in your code that I'd do differently are:

    • Error checking (always check the return value of open calls!)
    • Open the IP list for appending, at least. ">> listofips.txt". That way, you don't have to write the whole thing at once.
    • Setting $/ to undef and slurping the whole file into a scalar instaed of using read.
    But tracking IP addresses really isn't the way to go here, as merlyn and others have pointed out.