Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

variable. Consequently, if you wish to override the name of the session defined in
php.ini, you must do so prior to registering any variables or starting the session.


boolean session_register(...)


The session_register function accepts any number of arguments, each of which may
be a string or an array. Each argument names a global variable that will be attached to the
session. Arrays passed as arguments will be traversed for elements. You can even pass
multidimensional arrays. Each registered variable that is set when the script ends will be
serialized and written into the session information. When the user returns with a later
request, the variables will be restored.


string session_save_path(string path)


The session_save_path function returns the path in the file system used to save
serialized session information. This is /tmp by default. The optional path argument will
change the path. Keep in mind, the permissions for this directory must include read/write
access for the Web server.


session_set_save_handler(string open, string close, string
read, string write, string destroy, string garbage)


The session_set_save_handler function allows you to implement an alternative
method for handling sessions. Each argument is the name of a function for handling a
certain aspect of the session handling process. Unfortunately, at the time of this writing
the code that implements this functionality was not finished. Consequently, I can describe
the expected arguments, but I can't provide a working example. See Table 8.15.


boolean session_start()


Use session_start to activate a session. If no session exists, one will be created. Since
this involves sending a cookie, you must call session_start before sending any text to
the browser. You can avoid using this function by configuring PHP to automatically start
sessions with each request. This is done with the session.auto_start directive in
php.ini.


Once you start a session, PHP will begin watching the variables you register with
session_register.


boolean session_unregister(string name)


Use session_unregister to remove a global variable from the session. It will not be
saved with the session when the script ends.


Table 8.15. Functions for Use with session_set_save_handler
Function Argument
Free download pdf