Sessions and Cookies
In the previous examples I’ve accomplished the same tasks (log in and log out) using cookies and sessions. Obviously, both are easy to use in PHP, but the true question is when to use one or the other.
Sessions have the following advantages over cookies:
Generally more secure (because the data is being retained on the server)
Allow for more data to be stored
Can be used without cookies
Whereas cookies have the following advantages over sessions:
Easier to program
Require less of the server
In general, to store and retrieve just a couple of small pieces of information, use cookies. For most of your Web applications, though, you’ll use sessions. But since sessions do rely upon cookies by default, I’ll discuss how to better manage ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access