Session Examples

Use a subclass to provide the appropriate parameters to your session. Usually your subclass looks like this:

        class My_Session extends Session {
          var $classname = "My_Session"; ## Persistence support

          var $mode      = "cookie";
          var $lifetime  = 0;            ## use session cookies

          ## which container to use
          var $that_class = "Session_sql";
        }
 

Remember that you have to provide a DB_Sql subclass with the parameters needed to access your database.

Use the page management functions (see above) to use your session subclass. The feature name for session management is sess; provide the name of your session subclass as a parameter to the sess feature:

        page_open(array("sess" => "My_Session"));

Use the register() instance method to register variables as persistent. If $sess is your session object, use

        $sess->register("s");

to make the global variable $s persistent. $s may be a scalar value, an array or an object with persistence support slots.

Do not use the instance methods freeze() and thaw() directly, but use the page management functions instead.

To have some pages cached and others not cached, use multiple instances of the session object. For example, for those pages that should be cached, use a session object instance like

        class My_Cached_Session extends My_Session {
          ## pages that use this session instance are cached.
          var $allowcache = "private";
        }

Be careful when using the public cache option. Publically cached pages may be accessible to unauthenticated users. The private cache option prevents unauthenticated access, but is only functional in HTTP/1.1 browsers.