D
D
Dilik Pulatov2017-06-26 18:00:52
Database
Dilik Pulatov, 2017-06-26 18:00:52

How can I correctly implement like / dislike in a news site?

Hello!
in the news site, you need to implement a like / dislike .... I didn’t do this before,
the number of likes is saved in the database, but something needs to be done so that a person doesn’t like again and any person can like
there is an option: save each person in the database according to their ip address or something similar to this
or save it to the browser cache,
but I myself don’t want to save it in the database. and you can delete the cache and like it again .. what do you suggest?
(by the way, only weekly news is displayed on the site .... old news will not be displayed)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Vodakov, 2017-06-26
@WaterSmith

The IP address is not suitable as a user identifier, it can change, it can be given to another user. A cookie entry (cache) is also not good, a user can have several computers, a user can grant access from his computer to another user, in the end it can be a public computer. If you have a system of your likes on your site that is not tied to any social network. Then you need to do authorization, assign identifiers to users, and register likes for them.
As a like counter, it would be logical to store not just a news counter, but write a separate table: news id, user id, like, dislike. When a user puts a like, look for his id + news id in this table, and if there is, then put one in either the like or dislike field.
For the counter under the news, take the sum of likes, dislikes by news id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question