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()
Starts the session.
Session::start();
count()
Returns the number of elements in the session.
Session::count();
addTime(int $time)
Adds time to the session.
Session::addTime(10);
setTime(int $time)
Sets the session global time.
Session::setTime(10);
getRemainingTime([bool $gmdate])
Returns the session remaining time (in seconds).
Session::getRemainingTime();
If true
is given as parameter, it will return the remaining time with format (Hours, minutes and seconds).
Session::getRemainingTime(true);
empty()
Unset the session.
Session::empty();
kill()
Destroys the session.
Session::kill();
set(string $key, $value[, int $time])
Sets a session variable.
Session::set('name', $value);
get(string $key)
Returns a session variable.
Session::get('name');
has(string $key)
Returns true
if a session variable exists, false otherwise.
Session::has('name');
unset(string $key)
Unset a session variable.
Session::unset('name');
getVarTime(string $key[, bool $gmdate])
Returns the variable time (in seconds).
Session::getVarTime('name');
If true
is given as the second parameter, it will return the time with format (Hours, minutes and seconds).
Session::getVarTime('name', true);
setVarTime(string $key, int $time)
Sets the variable live time.
Session::setVarTime('name', 10);
addVarTime(string $key, int $time)
Adds time to a variable.
Session::addVarTime('name', 10);