Now that I know how to enable sessions, and have a better understanding of how they work, the next thing to do will be to make use of the session in some way.

But first, here are a couple notes I found in my reading:

  • The first time a user visits a page, SID will be set because the cookie doesn’t exist yet. That means that if you have the SID manually placed in your URL’s, or if Transparent SID Support is turned on, every search engine bot will pick up your links with session id’s added in.
  • The setting to make it so that cookies are required for sessions is session.use_only_cookies, in php.ini
  • If you need to add the SID manually in your URL’s, it *must* come first in the list of attributes, or it will not work.

So what to do with sessions? Obviously they’re used to store persistent data across multiple page loads. What that data is is up to the programmer.

To add an element to the session superglobal, do something like this:

$_SESSION['myValue'] = 1

In the next part, I’ll look at what can happen when more than one request is trying to access the session file at the same time.

PHP Sessions: Part 3
Tagged on: