https://github.com/phpgt/session
Encapsulated user sessions.
https://github.com/phpgt/session
cookie phpgt session-cookie session-handler session-management sessionstorage
Last synced: 9 months ago
JSON representation
Encapsulated user sessions.
- Host: GitHub
- URL: https://github.com/phpgt/session
- Owner: phpgt
- License: mit
- Created: 2017-11-05T17:24:57.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-19T11:08:00.000Z (over 2 years ago)
- Last Synced: 2025-04-19T23:45:09.593Z (9 months ago)
- Topics: cookie, phpgt, session-cookie, session-handler, session-management, sessionstorage
- Language: PHP
- Homepage: https://www.php.gt/session
- Size: 247 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Encapsulated user sessions.
This library is a simple object oriented alternative to the $_SESSION superglobal allowing application code to be passed encapsulated `SessionStore` objects, so areas of code can have access to their own Session area without having full read-write access to all session variables.
Sessions are addressed using dot notation, allowing for handling categories of session data. This is particularly useful when dealing with user authentication, for example.
***
## Example usage: Welcome a user by their first name or log out the user
```php
if($session->contains("auth")) {
// Remove the *whole* auth section of the session on logout.
if($action === "logout") {
$session->delete("auth");
}
else {
// Output a variable within the auth namespace:
$message = "Welcome back, " . $session->getString("auth.user.name");
}
}
else {
// Pass the "auth" store to a class, so it
// can't read/write to other session variables:
AuthenticationSystem::beginLogin($session->getStore("auth"));
}
```