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
nameThe 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::getYaf_Session::setYaf_Session::del