Wolff\Core\Session
Instead of managing the $_SESSION
variable directly, you can use the Wolff Session class.
It's safer since it's tied to the client's IP address and its user agent, meaning that if the client has a different IP or a different user agent, the session will be destroyed.
All the session methods works with the time expressed in minutes (unless it’s specified other way).
start(): void
Starts the session.
Session::start();
addTime(int $time): void
Adds time to the session.
Session::addTime(10);
setTime(int $time): void
Sets the session global time.
Session::setTime(10);
getRemainingTime([bool $gmdate]): mixed
Returns the session remaining time (in seconds).
Session::getRemainingTime();
If a string
is given as parameter, it will return the remaining time in the given date format.
Session::getRemainingTime('H:m:s');
empty(): void
Removes the session data.
Session::empty();
kill(): void
Destroys the session.
Session::kill();
set(string $key, $value[, int $time]): void
Sets a session variable.
Session::set('name', $value);
get(string $key): mixed
Returns a session variable.
Session::get('name');
has(string $key): bool
Returns true
if a session variable exists, false
otherwise.
Session::has('name');
unset(string $key): void
Unsets a session variable.
Session::unset('name');
getVarTime(string $key[, bool $gmdate]): mixed
Returns the variable time (in seconds).
Session::getVarTime('name');
If a string
is given as the second parameter, it will return the time in the given date format.
Session::getVarTime('name', 'H:m:s');
setVarTime(string $key, int $time): void
Sets the variable live time.
Session::setVarTime('name', 10);
addVarTime(string $key, int $time): void
Adds time to a variable.
Session::addVarTime('name', 10);