I have written myself a custom forum script using php. I decided against using phpbb and others as I wanted 100% flexibility with what I was doing.
I\'ve hit a problem
This is somehow a good question, I've never experienced this before so I could only suggest you an idea in which I have no guarantee about its correctness.
My idea basically is:
Create a new field, called is_new
inside a topic table. This field contains a list of values in string form, following a certain pattern. For example: 5|6|12|110|2|45
. Each value between |
represents a user's ID, who has read the topic.
Every time a user jumps into a forum, while fetching to return the list of topics, you will check if each topic is read by that user, simple by:
is_new
using explode('|', $row['is_new']);
in_array($user['id'], $list_of_ids);
If false
, mark the topic unread
, otherwise mark it read
and also update that user's ID into the is_new
list.
This approach seems less 'painful' than your original approach, since it only checks further more than ordinary, and as simultaneously as you fetch the list of topics. I think it will affect a little bit more if you have heaps of users.
Note: you don't have to worry about the problem of normalization since is_new
contains multiple values, you only use it to check and update, no selection required.
In addition, alternatively, you can check the topics are new or not using time comparison. For example, if a topic lasts for 4 weeks and a user doesn't read it, then it returns old even though it's unread (it makes sense doesn't it? Just like a newspaper). I think you will be able to do this, quite easy indeed.
This approach is particularly applied by quite a few forum software, since it is quick and makes more sense. Remember that the browsers initially support you with determining read/unread topics, i.e. the color of hyperlink to the topic will be changed if it's visited. Now it turns back to the Cookies solution. I wouldn't worry about users deleting their cookies. This happens rarely and the users won't die just because the read
topics turn unread
after they delete the cookies.
Quite an open-ended topic isn't it? Hope this helps (: