I am currently making a simple list tool. You can click a checkbox to mark it as done and if you navigate away from the page/close the browser and reload, it will still be saved. So it's pretty much just a visual difference.For this, I'm wondering, should I use PHP or Javascript to set a cookie to save the data on whether or not the item was checked?If not, should I use $_SESSION? I haven't been able to find a simple solution relevant to my concern, from my searches almost all of them are related to saving usernames/passwords, which of course have an added security aspect too.Thanks.
Should I save a simple list cookie in Javascript or PHP?
php;javascript;session;cookies
For the choice there are multiple questions to be asked. How relevantis the data, is it shared across browsers, howl on should it live etc.Cookies are bound to a specific browser. The lifetime can be set from during this browser session to some arbitrary date in future. This doesn't mean the lifetime will be reached as there are different events at which a browser might kill the cookies. If its only you and your browser this might work .. ut the list might suddenly be lost.PHP Session storage is stored on a server and referenced by a cookie or URL parameter. It has a relatively short lifetime (by default 24 hours) as by default the session files reside in the /tmp directory a cleanup process (ie. on server reboot after power failure or update) might delete them. Still not persistent. (PHP session handling could be configured in a quite persistent way but that's ignoring the purpose)So both probably aren't good. Alternatives? Yes there are!HTML 5 introduces browser local storage for more data. That is useful to have nicer access to the data and more flexibility in usage. Downside is that this still depends on using the same browser all the time and somecleanup miht free it unexpectedly.A more robust solution is to use some server-side (PHP) script which stores the list in a database (or simple file) in a place where it is unaffected from cleanup tasks. By that the list can be access from different browsers (i.e desktop and mobile device) and won't easily go away.