php8.5
Home/ Manual/ yaf / yaf_session/ Yaf_Session::set

Yaf_Session::set

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Set a session value

Description

Yaf_Session::set(string $name, mixed $value): bool

Sets a session value.

Parameters

name

The session key to set.

value

The value to store.

Return Values

Returns true on success, or false on failure.

Examples

Yaf_Session::set example

php
<?php
class LoginController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        // ... verify the credentials against the database
        $session = Yaf_Session::getInstance();
        $session->start();

        $session->set("user_id", $user->getId());
        $session->set("login_time", time());

        return $this->redirect("/dashboard");
    }
}
?>

See Also

  • Yaf_Session::get
  • Yaf_Session::has
  • Yaf_Session::del

Source: reference/yaf/yaf_session/set.xml · from the official PHP manual (php/doc-en)