From the course: PHP with MySQL Essential Training: 2 Build a CMS

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Set and read session values

Set and read session values

- [Instructor] In this movie, we'll learn how to use PHP to set and read values in the session file. In order to set a value in the session, all we have to do is use the super global and assign a value to a key, just like we would any associative array. It's that simple. We don't have to use a special command like we did with set cookie. Here we just simply talk to the associative array and PHP will then store that value in the SESSION file for us. That's very different than when we're working with the cookie. We have a live connection, alive association between the contents of our session file and the super global session. When we want to read a value back, then we just simply asked for the value that relates to that key for these associative array. So here I'm asking for SESSION lang and I would get back the value English. Now it's a good idea to make sure that that value exists. Otherwise, if we asked for a key in an associate array that doesn't exist, we'd get an error. So you…

Contents