From the course: Learning PHP

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Maintaining state with sessions

Maintaining state with sessions - PHP Tutorial

From the course: Learning PHP

Start my 1-month free trial

Maintaining state with sessions

- [Instructor] Cookies are great for maintaining state, but one problem with this is they're on the user's computer. That means the user might be able to modify the value of a cookie. That's fine if you're storing simple data like their name or if they're logged in, but what if you're storing something like shopping cart data or other information that shouldn't be modified by the user? That's where sessions come in. Sessions like cookies expire when the browser closes, but the sessions are stored on the server, which users can access. Another benefit of sessions is they can be set at any time, unlike cookies, which need to be set before anything is output onto the screen. So for our sessions example, let's modify our mailing list. Let's say we only want to show this form to people who haven't signed up for the mailing list. That way, if people who have signed up visit the page, they won't be able to sign up again. So the…

Contents