WriteCookie() (v2024)

Hi,
v2024
trying to write a value to a cookie in userfn.php via a function

function _hideOnboardCheckList() {   

                WriteCookie(
                    "dismissGetStarted",
                    "1",
                    time() + Config("REMEMBER_ME_EXPIRY_TIME"));

    return;    
}

the return statement is never hit,as it appears it never returns from Write Cookie, and the cookie isn’t written.

looks like an error is triggered:

{
    "statusCode": 200,
    "error": {
        "class": "text-danger",
        "type": "Error",
        "description": "C:\\xampp\\htdocs\\dams\\vendor\\dflydev\\fig-cookies\\src\\Dflydev\\FigCookies\\FigResponseCookies.php(26): Dflydev\\FigCookies\\FigResponseCookies::set(): Argument #1 ($response) must be of type Psr\\Http\\Message\\ResponseInterface, null given, called in C:\\xampp\\htdocs\\dams\\src\\phpfn.php on line 890",
        "trace": "#0 C:\\xampp\\htdocs\\dams\\src\\phpfn.php(890): Dflydev\\FigCookies\\FigResponseCookies::set(NULL, Object(Dflydev\\FigCookies\\SetCookie))\n#1 C:\\xampp\\htdocs\\dams\\src\\phpfn.php(934): PHPMaker2024\\dams\\SetCookie('dismissGetStart...', '1', 1763352160, false)\n#2 C:\\xampp\\htdocs\\dams\\src\\userfn.php(2024): PHPMaker2024\\dams\\WriteCookie('dismissGetStart...', '1', -1)\n#3 C:\\xampp\\htdocs\\dams\\src\\userfn.php(2285): }

Thanks,

If you write cookie before the HTTP response is created, you should use PHP’s setcookie() directly.

Hi,

yes, we tried that, the setcookie() call, appears to redirect to the phpfn.php:

function SetCookie($name, $value, $expiry = -1, $httpOnly = null)
{
    $Response = FigResponseCookies::set($Response, $setCookie); // ERROR   
    return $setCookie;
}

with the same error result.

here is the userfn call:

function _hideOnboardCheckList() {
    
    setcookie("dismissGetStarted", "1");
    return;    
}

resolved by:

write in js:

Cookies.set('dismissGetStarted', 1, { expires: 365 });

read in php:

        $dismissGetStarted = @$_COOKIE["dismissGetStarted"];
        if($dismissGetStarted)
            $item->Allowed = false;