"Poe_Session", "auth" => "Poe_Auth", "perm" => "Poe_Perm", "user" => "Poe_User")); // page access requires that the user is authenticated and has "admin" permission $perm->check("admin"); // s is a per session variable, u is a per user variable. $sess->register("s"); $user->register("u"); ?>
Reload this page to see the counters increment.Per Session Data is available only on pages using the feature "sess" in their page_open() call. Per User Data: %s\n", ++$u); ?> Per User Data is referenced by user id. The user id is stored as a session variable in each authenticated session.
Per User Data is only available on authenticated pages (pages using the feature "auth" in addition to the feature "sess"). It is activated with by using the feature "user".
The name is an identifier for a namespace. Usually it is the name of the class that creates ids. For example, Poe_Session is the name of the class managing session variables in this example and Poe_User is the name of the class managing user variables in this example.
The sid is a unique identifier within a namespace. Both, name and sid together can be used as a key into the active_sessions table. The identifier should be hard to guess and not predictable. That is why we use 32 character md5() strings of values created by uniqid().
The val is where the data associated with a name/sid pair is stored. Data is stored in the form of a PHP program that recreates the values stored. The string retrieved from val is later fed to exec() in PHP. Since val can become a pretty large string, we use a blob or a similar large datatype to store it.
The changed value indicates when the last write into that particular row of the table has occured. It is used by the gc() functions (garbage collection functions) of their respective owner classes. The gc() of a class will delete all rows belonging to that class (name is being checked) that have not been written to for a given number of minutes. The gc() is called randomly with an adjustable probability. query("select * from active_sessions order by changed desc"); // $t is reused... printf("
You will find two different types of entries in this table, distinguished by the value in the name column. Poe_Session entries belong to per session data. Poe_User entries belong to per user data. The actual data is visible in the val column.
Within that val column you find an executeable PHP program. This programs contains assignments only. You will find two types of assignments: Assignments to internal class variables ($this->pt assignments) and assignments to global variables ($GLOBALS assignments).
Assignments to internal class variables are used by the saving class itself so that it can remember which variables are to be saved. These assignments record the names of all global variables that are to be saved by that class. For example, if there is a Poe_Session that contains the statements $this->pt["auth"] = 1; $this->pt["s"] = 1, you can see that the global variables $auth and $s are per session variables.
Later in that string you will find other assignments to $GLOBALS["s""] that store the current value of $s. Since $s is a scalar variable in this example, you will find only a simple assignment.
You will also find a lot of assignments to $GLOBALS["auth"]. Since $auth is an object, it cannot be reconstructed with a single assignment, but needs multiple instructions to reconstruct the full objects.