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

Yaf_Session::del

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Remove a session key

Description

Yaf_Session::del(string $name): bool

Removes a session key and its value.

Parameters

name

The session key to remove.

Return Values

Returns true on success, or false on failure.

Examples

Yaf_Session::del example

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

        $expected = $session->get("captcha_code");

        // one-time code: remove it right after use
        $session->del("captcha_code");

        if ($expected === null
            || $this->getRequest()->getPost("code") !== $expected) {
            echo "invalid captcha";
        }
    }
}
?>

See Also

  • Yaf_Session::get
  • Yaf_Session::set
  • Yaf_Session::has

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