PHP 8.6.0 Beta 2 available for testing

Yaf_Request_Abstract::getCookie

(Yaf >=3.2.2)

Yaf_Request_Abstract::getCookieFetch a COOKIE variable

Beschreibung

public function Yaf_Request_Abstract::getCookie(string $name = ?, mixed $default = ?): mixed

Retrieves a variable from $_COOKIE.

Parameter-Liste

name

The variable name. If omitted, the whole array is returned.

default

The value to return if the variable is not found.

Rückgabewerte

The cookie value, or default if it is not set.

Beispiele

Beispiel #1 Yaf_Request_Abstract::getCookie() example

<?php
class UserController extends Yaf_Controller_Abstract
{
    public function profileAction()
    {
        $request = $this->getRequest();

        $theme     = $request->getCookie("theme", "light");
        $sessionId = $request->getCookie("sid");

        var_dump($theme, $sessionId);
    }
}
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

string(4) "dark"
string(8) "1f2a3b4c"

Siehe auch

add a note

User Contributed Notes

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