PHP 8.6.0 Beta 3 is available for testing

Yaf_Session::has

(Yaf >=1.0.0)

Yaf_Session::hasCheck if a session key exists

Description

public function Yaf_Session::has(string $name): bool

Checks whether a session key exists.

Parameters

name

The session key to check.

Return Values

Returns true if the key exists, false otherwise.

Examples

Example #1 Yaf_Session::has() example

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

        if (!$session->has("user_id")) {
            $this->redirect("/account/login");
            return false;
        }

        return true;
    }
}
?>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top