In the frontend my website sets a cookie wich i need during a controller action. When calling the controller action from my plugin this Cookie gets duplicated and the value is replaced with an identifier.

BEFORE CALLING CONTROLLER: enter image description here

DURING CONTROLLER ACTION: enter image description here

As seen in the screenshot above the original json value of the Cookie is replaces with an integer. I have tried different methods to get the cookie but no success.

Cookies::$plugin->cookies->get("downloads-1") \\Returns 1649671559
Craft::$app->request->cookies->get("downloads-1") \\Returns null
$_COOKIE["downloads-1"] \\Returns 1649671559

How can I get the original value of my cookie in my controller?

PHP version 7.4.16
Craft edition & version Craft Pro

1 Answer 1


Craft uses Yii's cookie handling, which includes cookie validation, resulting in cookies being signed with a hash string. To retrieve a plaintext (unvalidated) cookie, use PHP's global variable $_COOKIE.

$value = $_COOKIE['downloads-1'] ?? null;

From your screenshot, it looks like something unrelated created a session cookie of the same name. Look at the path to start troubleshooting where it might have been set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.