Answer the question
In order to leave comments, you need to log in
Implementation options read/new comments?
The goal is for users to separate read and unread comments. Implementation example - habr.
Where to store, except for the database? Cookies? In any form?
Answer the question
In order to leave comments, you need to log in
Write the session in cookies, store the data on the server in the database for this session. Will go from another place, lose current data, get a new session. It's okay, you can't put a stigma on a specific person.
no storage whatsoever. When entering, give the user a cookie and bind its value to a record in the storage.
Only go for a compromise, if everyone is not registered, then by logging in from another computer or browser, they will again have all the comments unread, this is the first compromise. Second, if they want to change computers and browsers, let them register. Otherwise, there’s no way, ip can change, the browser and cookies, respectively, too, bind only to their input when entering the website of your passport :) or inn :)))
Write to cookie or session id of last read comment. At the next request, those with id > stored will be unread.
Everything is clear with the database, I want to consider everything except it
Yes, you can use cookies. One cookie max. 4 kb = info for 4096*8 comments. + total 20 cookie entries. And that 4096*8*20*0.95 (any special characters) = 620,000 comments can be stored in cookies.
1 - read
0 - not read.
But this is very difficult, in terms of - you need to determine which bits belong to which comment, a strong blow to traffic.
If the number of comments goes off scale, it's a disaster.
Oh, here they wrote a topic about Last-Modified especially for you .
Each comment has a timestamp. The browser sends an If-Modified-Since header on the request.
If changing computers by users is a real scenario that you want to implement, there is a half-hearted solution - put a link like “already read this” next to the comments, which will mark this and all earlier comments as read. That. the user will restore their reading history in one click.
True, this is not a very common method, so users will have to be trained.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question