I’m currently working on a chat that heavily relies on JavaScript and which uses node.js for the backend. I’d like to do as much as possible in JavaScript (maybe even no PHP at all if possible). One of the problems I ran into is how to hold the state of the site. When a user clicks on a contact the content of the communication is fetched from the server.
What would you suggest to save the id of the currently displayed contact. Anchor? Variable? Cookie?
Cookies are used for a relatively long-term usage by your website, specifically when you want to keep some data client-side which was custom-tailored for the user at hand (and doesn’t jeopardize your system). So, when he (or she) revisits your website, it will be as they left it – without you storing unnecessary per-user data in the database. So, from the definition, that’s a no for cookies.
Your problem is more of an immediate-usage nature – you’re working with the id of a currently displayed contact and that is perhaps best suited for a variable (from the offered), or perhaps even the DOM – as jfriend00 pointed out.
And, a piece of general advice, do consider standard security implications and code defensively.
Happy coding!