|[ Team LiB ]|
What Are Session Functions?
Session functions implement a concept you have already seen. That is the provision to users of a unique identifier, which can then be used from access to access to acquire information linked to that ID. The difference is that most of the work is already done for you. When a user accesses a session-enabled page, she will either be allocated a new identifier or reassociated with one that has already been established for her in a previous access. Any variables that have been associated with the session become available to your code. If the php.ini register _globals directive is set, session data becomes available in the global namespace. Otherwise, you can access them through the superglobal $_SESSION associative array. Remember that register_globals is disabled by default, so it is generally the best policy to work with the $_SESSION array.
Both the techniques for transmitting information from request to request that you looked at in the previous hour are automatically supported by PHP's session functions. Cookies are used by default, but you can ensure success for all clients by encoding the session ID into all links in your session-enabled pages.
Session state is usually stored in a temporary file, although you can implement database storage using a function called session_set_save_handler(). session_set_save_handler() is beyond the scope of this book, but you can get more information at http://www.php.net/manual/en/function.session-set-save-handler.php.
|[ Team LiB ]|