If you want to do it the way Facebook does, you will need to send AJAX requests to another of your pages at regular intervals, in the case of Facebook, this is every time you send a message. This page parses the AJAX request and updates it in the database. When you refresh the page, the database is called to see what to show in the chat.
The problem with using a cookie is the size limit (Facebook can store chat days using a database).
You also do not need to worry if the client has disabled cookies, because all information is stored on the server.
source
share