Hello, you need to make a vote on more than 100 pages (something like evaluation of the article). He began to think how to implement it, and stopped to check whether this person had already voted or not (to avoid a repeat vote). Because On the website there will be a registration I stopped at the following version:

A person is registered, after which he can vote (unregistered users cannot vote). After that he votes and his login is entered into the database and a cookie is created for example with check=true .

* For each article in the database there will be a column with the logins of the voters.

Then there will be a check, if check=true , then remove the button for voting. Even if a person cleans up a cookie, then the following check will be: If there is a cookie then there will be no check in the database. But if it does not exist, then we check login==$login and do a cookie with check=true

The right decision or not? Maybe there is much easier options?

AMENDMENT:

Who creates a database for such things? There are 2 options: 1) Make 1 table where ALL votes will go. Of course, the voting ID will also be entered there. 2) Create tables for each vote separately.

  • one
    What is a cookie for? Why not check the entire database while checking? Or do you want to pull the database only when trying to vote? - cheops
  • Namely, I don’t want to do a database search once again. - Leonid

1 answer 1

in the database, I would make a table with a primary or unique key of two fields at once: article_id and user_id - this guarantees in the data itself that one user votes only once.

When authorizing, I would give an array with the listed article_id to the json client in which the user has already voted, so as not to even suggest that he do it again there. This is better than cookies, as it does not bind to the computer, browser, and its potential unwillingness to work with cookies.

  • you can still write in session - Naumov