The best way to implement "remembering" multiple values ​​in a web application

On poll sites, a user (not logged in) can only vote on one question. How does the web application "remember" that the user has already answered a specific question?

one way is to set a cookie for every question she answers. another way to store the question id in the session. we could also store the value in db along with the session id.

Is there any other way to do this?

0


a source to share


7 replies


You can also try to do this with the user's IP address. The value is to store the IP address that answered the question. The problem with using session is that the user can always clear their cache / cookies and then go back to your site and vote again. They can spoof their IP address too, but this is at least a little more complicated. The combination of both storing in the session and in your DB is the most reliable (and easiest) way IMO.



+1


a source


Depends on how long you need to remember.

The cookie solution will not work for clients who will not accept cookies.



Storing responses to response IDs in a session works fine as long as the session is alive, but you waste memory when the session is invalid or timed out.

Storing response IDs in a database is the most durable and reliable. I would recommend that you don't store the session id as it doesn't make sense. A timestamp showing when the question was answered, along with the answer, may be more appropriate.

0


a source


I would recommend using a cookie because you can store it on the user's computer and if you don't change to another machine, delete their cookies or browsers, they will be there. Since you have no logins, this is the easiest way to track a specific user. If you try to complete a user's session, the session information will expire and they can go back and vote again.

0


a source


You can save your responses to the server in an XML file (one per user / ip /?). You still need to have some sort of authentication or a way to associate the user with an existing file when starting a new session.

Hope it helps,

Bill

0


a source


is there any other way to do this?

No. Of course, there are no good ways, at least.

0


a source


If I use cookies, shd Do I store each question ID (and answer) in a separate cookie? that would mean a lot of cookies, right? say if a user answers 50 or 100 questions, will that be a lot of cookies? this is normal?

0


a source


I checked with polldaddy. I cleared the session and cookies, it still remembered my choice. Looks like they are using an IP address

0


a source







All Articles