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?
a source to share
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.
a source to share
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.
a source to share
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.
a source to share