ClassGo
Session\Manager
class Session\Manager {
- public string $session_cookie_name;
- public function __construct(object $storage, object $users);
- public function delete_by_user(string $user_id): int;
- public function destroy(): void;
- public function get(): string;
- public function login(string $key, string $secret): bool;
- public function set_auth(object $users): void;
- public function set_storage(object $storage): void;
- public function start(mixed $user_id): void;
- public function valid(): bool;
}
Description
Session\Manager starts, reads and validates the request's session against the given $storage, and logs a user in against the given $users. With no arguments it takes disk storage and the application's own .htpasswd and `new Session\Manager` is a working login.
The default store opens the file and defers the parse to the login that reads it: a manager constructs on every request, and a page that never calls login() does not pay for the account list.
Session\Manager is a class phpscript declares.
$object = new Session\Manager($storage, $users);
Properties
-
SessionCookieName is the mutable name this package reads and writes the session cookie. PHP may change it with `$session->SessionCookieName = "sid"`.
The go field
SessionCookieName.
Methods
public function delete_by_user(string $user_id): int-
delete_by_user signs one user out of every client, answering how many sessions it took. It clears this manager's own session when the sweep took it and valid() answers false in the same request the account went away in.
The go method
DeleteByUser. public function destroy(): void-
destroy ends the current session: it drops the data behind the cookie and expires the cookie on the way out.
A session that is not there is no error. Logging out twice, and logging out of a session a prune already took, are the same request to the client, and both end with no session and no cookie.
The go method
Destroy. public function get(): string-
get returns the user ID stored for the current session cookie.
The go method
Get. public function login(string $key, string $secret): bool-
login authenticates $key and $secret against the user database and starts a session for the user it names. It reports whether the credential held; a wrong password is false and no error.
The session carries the user's primary key and a row written during the session references the user the way any other table does. The username stays in the user database, and a caller that needs it reads it there.
The go method
Login. public function set_auth(object $users): void-
set_auth replaces the user database login() authenticates against.
The go method
SetAuth. public function set_storage(object $storage): void-
set_storage replaces the storage sessions live in.
This is the setter half of the constructor: a script that took the manager's defaults and then needs memory storage says so here, and the rest of the manager holds. It wraps the storage for tracing as the constructor does and the trace names whichever backend answered.
The go method
SetStorage. public function start(mixed $user_id): void-
start creates a new session, stores userID, and stages its HTTP-only cookie.
The go method
Start. public function valid(): bool-
valid reports whether the request has a well-formed cookie whose session is present in storage. Missing and malformed cookies are invalid, not errors.
The go method
Valid.
Binding
- The go type
github.com/titpetric/phpscript/stdlib/session.Manager. - Registered by the package
github.com/titpetric/phpscript/stdlib/session. - Built on
github.com/titpetric/phpscript/stdlib/session.Manager.