Check if client has already voted

530
December 08, 2016, at 11:15 PM

I am making a poll site. And for making sure that people can't vote twice I'm saving their IP with the ID for the poll in a database. But this requires me to send the IP from the client to the server to retrieve the data out of the database. I am doing this all on the button: Vote so it checks when you click vote.

Now I am using Express and socketio and Node.js. I can't really figure out how to retrieve the IP.

The user does not have to register to vote or create a poll.

The method above might not be the best one and I think there might be a better one. So my question is:

What would be the best way to check if someone has already voted on a poll.

Answer 1

If you want to find the IP address, inside your express application:

app.get('/ip', function (req, res) {
    var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress;
    //do whatever you want with it
});

And to answer your question, personally I'd require the user to type some sort of unique identification, like a university id number, tax number (thats how we're identified here in Brazil for example), anything that you can guarantee is unique to only one individual in your area of interest.

If you can't get something like that, I guess you'd have to register your users.

Rent Charter Buses Company
READ ALSO
I want to create Menu with Javascript [on hold]

I want to create Menu with Javascript [on hold]

I write this code in my Javascript external file but when use code in browser, console returns me that canot read property style of nullwhat the problem ?

383
Cannot read property 'geocode' of null / Code working only when debugging

Cannot read property 'geocode' of null / Code working only when debugging

I have this code that creates a map and places markers on it

290
AJAX/JQuery function undefined

AJAX/JQuery function undefined

I'm working on a project that allows users to invite other usersWhen a user gets an invite, a pop-up should, well

447
How to Count Matched Elements in ArrayList in Java

How to Count Matched Elements in ArrayList in Java

i have question about how to count matched elements in ArrayList in javaEx: My ArrayList contain [sport, sport, ball , player, sport]

479