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

Yaf_Session::has

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Check if a session key exists

Description

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

Yaf_Session::has example

php
<?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

  • Yaf_Session::get
  • Yaf_Session::set
  • Yaf_Session::del

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