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

Yaf_Session::get

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Get a session value

Description

Yaf_Session::get(string $name = NULL): mixed

Retrieves a session value by name. If name is omitted or null, the entire session array is returned.

Parameters

name

The session key to retrieve, or null to get all session data.

Return Values

The session value, or null if the key does not exist. When name is null, the full session array is returned.

Examples

Yaf_Session::get example

php
<?php
class ProfileController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $session = Yaf_Session::getInstance();
        $session->start();

        $userId = $session->get("user_id");
        if ($userId === null) {
            return $this->redirect("/account/login");
        }

        echo "welcome back, user #", $userId;
    }
}
?>

See Also

  • Yaf_Session::set
  • Yaf_Session::has
  • Yaf_Session::del

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