http://www.perlmonks.org?node_id=2350

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

What would be an efficient and easy way to check and log a user's IP adress and make sure that someone would not be able to vote more then once in a polling script? I am not exactly sure how to do this. Is there another script which I could view this process or a web site that makes reference or is it an easy code to write on this board?

Replies are listed 'Best First'.
Re: Checking user's IP....
by davorg (Chancellor) on Feb 02, 2000 at 01:31 UTC

    Doing it with an IP address is no good as:

    • All AOL users come from a limited number of IPs.
    • Many ISPs allocate users a new IP each time they connect.

    Far better to do some kind of user login.

    hth
    davorg

Re: Checking user's IP....
by turnstep (Parson) on Mar 30, 2000 at 05:05 UTC

    User logins will drastically reduce your number of respondants, of course. You could use a simple cookie. Something like VotedPoll1=451234221 where the number represents the time, to make it easy to allow voting again at a later time. Although it might be easier just to number the polls if a new one is created every day.

RE: Checking user's IP....
by vroom (His Eminence) on Jan 23, 2000 at 05:02 UTC
    You could log the IP addresses to a file and then search it. If you're running your site with a database you could log them to a table.
    $address=$ENV{REMOTE_ADDR}; open FILE, "<logaddresses.dat"; my $addresses; { local $/=undef; $addresses=<FILE>; } close FILE; if($addresses=~/\Q$address/){ print "You already voted\n"; } else{ open FILE, ">>logaddresses.dat"; print " $address\n"; close FILE; # update poll; } #display results;
    if you want code for a database solution let me know
      I had the code checking user IP but I need the code to search IP address and if IP address is found, redirect to the found IP address by connecting open connection to telnet using the found IP address. I would appreciate if you could help me with this code. Thanks
Re: Checking user's IP....
by dlc (Acolyte) on Jan 24, 2000 at 17:00 UTC

    if you are using a database, then use the voter's I address as the key, and declare (in the database description) that the key be unique.

    this isn't really the best idea, though--you'll shut out (potentially) tons of visitors that come from the same IP, such as a proxy server (ahem, *AOL*, ahem) and allow the same user to vote if he is coming from an ISP which uses dhcp to assign addresses.

Re: Checking user's IP....
by Anonymous Monk on Jan 23, 2000 at 11:54 UTC
    vroom, thanks for that code. I have one more question, is there a possible way to clear the log file after one day so people can vote once a day or would I have to clear it myself daily?
      You have several options here.
      1. Have the name of the file contain the date.
      2. Have the date as the first line of the file. If the dates are different, remove the file.
      3. Have the perl script accept the poll's name from a form hidden. Search only that file.
      Of these options, I like the last one best. This will allow you to accurately track the results of your polls. (as a back up to the main mechanisim.) And it would allow you to keep up past polls. And you could leave a poll up for longer than a day.

      Crulx

      Damn cookies. *giggle*

      You have several options here.

      1. Have the name of the file contain the date.
      2. Have the date as the first line of the file. If the dates are different, remove the file.
      3. Have the perl script accept the poll's name from a form hidden. Search only that file.
      Of these options, I like the last one best. This will allow you to accurately track the results of your polls. (as a back up to the main mechanisim.) And it would allow you to keep up past polls. And you could leave a poll up for longer than a day.

      Crulx