views:

324

answers:

3

This is the million dollar question, I see it time and time again on here and other php coding related sites and forums but I have NEVER seen an answer to it.

So I started digging in and studying how some of the big high traffic forums accomplish this feature of showing you which threads have new unread posts in them and it appears that they store the thread ID number into a user cookie. So there would be a cookie with a thread ID of every thread you have read within a certain amount of time. Or something similar to this.

I then read on here that cookies can only store X amount of characters, so I am wanting to know how much data can be stored in a cookie? If I have a 5-6 character ID number, how many could I fit into a cookie?

A: 

cookie limit in ie :

at most 300 cookies

at most 4096 bytes per cookie (as measured by the size of the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie header)

at most 20 cookies per unique host or domain name

Haim Evgi
do you mean 'at most'?
LukeP
yes , thanks i edit
Haim Evgi
A: 

I don't think they use cookie since that isn't going to persist if you switch computers (unless it's DB-based cookies that some frameworks provide). I'd assume they have a relationship table in the database that keep track of the latest date a user viewed a thread.

Parrots
if you go to some big forums which use vbulletin andphpbb, then view your cookies you will see there is a cookie with many thread ID's, also if you view the source code you can see they are adding the ID to a cookie when you view the thread
jasondavis
@jasondavis, I think Parrots is trying to say show the unread/read status cannot be 100% cookie based due to the fact if the user were to switch computers and then view the forum, there would be no record of unread/read status. And due to that, it must be something else.
Anthony Forloney
+1  A: 

More importantly though, the cookie specification says that browsers need only accept 20 cookies per domain. This limit is increased to 50 by Firefox, and to 30 by Opera, but IE6 and IE7 enforce the limit of 20 cookie per domain. Any cookies beyond this limit will either knock out an older cookie or be ignored/rejected by the browser.

Taken from this author's post

I believe for the unread/read status of forum posts should be done through the database. I could not find an example online, but I have read "PHP and MySQL Web Development (4th Edition)" and they have a section devoted to developing your own forum page. They supply example code and explain the process to get it started.

Anthony Forloney