Comparing ip adres with database list

I’am creating a pollsystem for my site.
so on each vote in the database the ip adress of the person that vote is
logged.
But how can i make that when somebody vote this ip adress not voted
before.

So how can i compare the list of ip adresses with the new one

I am unsure what you mean. But what I would do is drop a cookie with a
(semi) unique number and store that number in a database. Unless it is
very important users can’t vote more than once. The problem with
logging IP’s is that there could be more than one PC behind a single
IP. And this is quite often the case.

If a user comes to your site you simple retrieve the cookie with the
number and see if the number already exists in the DB, if so the
person already voted, if not he did not.

On Jul 25, 3:38 pm, GA Gorter [email protected]

On 25 Jul 2007, at 15:38, GA Gorter wrote:

I’am creating a pollsystem for my site.
so on each vote in the database the ip adress of the person that
vote is
logged.
But how can i make that when somebody vote this ip adress not voted
before.

So how can i compare the list of ip adresses with the new one

How about something like (code can be made shorter, but I’ll keep it
nice and easy to understand):

if Vote.find(:first, :conditions => [“ip_address = ? and poll_id
= ?”, request.remote_ip, params[:poll_id]])
flash[:notice] = “You’ve voted for this poll already”
# Do a redirect, reder or render something using AJAX
else
new_vote = Vote.new(params[:vote])
new_vote.ip_address = request.remote_ip
assigned_poll = Poll.find(params[:poll_id])
assigned_poll << new_vote if assigned_poll && new_vote.valid?
# Do a redirect, render or render something using AJAX
end

Best regards

Peter De Berdt

On 25 Jul 2007, at 16:26, harm wrote:

I am unsure what you mean. But what I would do is drop a cookie with a
(semi) unique number and store that number in a database. Unless it is
very important users can’t vote more than once. The problem with
logging IP’s is that there could be more than one PC behind a single
IP. And this is quite often the case.

If a user comes to your site you simple retrieve the cookie with the
number and see if the number already exists in the DB, if so the
person already voted, if not he did not.

I would combine the two and even store the vote in a session variable
for extra security if users have to log in to vote (it all depends on
how important the unique votes are). Simply said: internet voting can
always be tampered with:

  • People can change their IP (most ISPs use DHCP, so resetting the
    modem gives your user a new IP)
  • People can delete cookies
  • People can quit their browser, thus resetting the session

The more security you put in place, the more you’re disencouraging
your user search for a way to cast additional votes.

Best regards

Peter De Berdt

Thanks for the code Harm my site is working very well now.

@peter That’s true it’s very simple to have another ip adres my neigbors
have an unprotected wireless network. But this was a project just for
fun. Now i have a pollcode i think i will make it better and intergrate
in some of my other projects.