-
-
Notifications
You must be signed in to change notification settings - Fork 1
User_Session
You may need to import this feature on top of your code.
use \Scarlets\Library\User\Session;
It's better for not using the framework's build-in server
The session configuration are stored on /config/session.php
.
This feature is supposed for handling user session who was accessing the website server. The session can be saved inside the client browser using cookies or server database. When you're using this library, it will automatically add sessions
table on the database if not exist.
Column | Description |
---|---|
id | Session ID to maintain data relation |
session | Text ID of this session |
data | JSON encoded data of this session |
ip_address | Last IP Address |
last_url_access | Last URL Access |
last_limited_access | Limited access counter |
last_access_time | Last access timestamp |
last_created | Timestamp when this was created |
blocked | Is user session blocked? |
When you're using this feature, this will automatically being initialized by the framework. After the session was initialized, the data from database and client side session data will be loaded. And when the PHP was done (on shutdown event), it will automatically being saved to the database and client browser.
Session::$sify = []; // From Client
Session::$data = []; // From Database
# The current Session ID
Session::$ID = false; // Numeric ID
Session::$TextID = ''; // Text ID
Session::$FullTextID = ''; // SFSession
By storing the data in the client side, you will have to prevent any body response being sent before the Set-Cookie
header was being sent. This will return true on success.
// Set the data and the send it to the client.
Session::$sify = [
'key'=>'value'
];
Session::saveSify($force = false);
// Or another alternative for setting and saving data
Session::sify([
'key'=>'value'
]);
When storing session data to the server database, the data will be automatically saved when the App was finished.
Session::$data = [
'key'=>'value'
];
But in some case, you can immediately save the session to the database. When the SessionID is exist in the database, this will try to update it. But If you force set $new
to true, this will create different session.
$id = Session::save($new = false);
This will help you to remove the current session on the client browser and the database server.
Session::destroy($justCookies = false);