Search⌘ K
AI Features

Using Sessions for Storing User Data

Understand the difference between sessions and cookies in PHP, and learn how to use sessions to securely store and retrieve user data across web requests. This lesson explains starting sessions with session_start, how PHP manages session IDs, and ensures session data integrity on the server.

Sessions vs. cookies

Manipulation and visibility of cookie content

We saw how you can use cookies to pass data between requests. We ended with a warning that cookies can be manipulated, because they are headers, so they can’t really be trusted. Another security aspect is that the contents of cookies are visible. Both of these aspects of cookies make them unsuitable for sensitive information, or information that only you as the programmer should be able to manipulate.

  ...

Sessions come to rescue

For situations where using a cookie isn’t a good idea, but you still want to keep some kind of information between requests, you can use a session ...