CraftQuest Casual 02

Ryan is back for the second installment of CraftQuest Casual with talk of current work and some thoughts on cookies (in Craft CMS and Yii).

Streamed on March 27, 2025

In this livestream, Ryan shared his cur­rent projects, which includes adding user-adjust­ed time­zones and times for upcom­ing livestreams.

He cre­at­ed this func­tion­al­i­ty using a Craft CMS mod­ule in the CraftQuest project, but along the way learned more about how cook­ies are han­dled in both Craft CMS and Yii.

We explored when and why you might need to use getRawCookies() instead of the stan­dard cook­ie col­lec­tion — par­tic­u­lar­ly when deal­ing with JavaScript-set cookies.

When cook­ies are set via JavaScript, they lack the secu­ri­ty sig­na­ture that Yii applies to serv­er-set cook­ies. Con­se­quent­ly, these client-side cook­ies fail Yii’s val­i­da­tion process and become inac­ces­si­ble through the stan­dard cook­ies col­lec­tion. If you try to access a JS-set cook­ies via getCookies(), it will fail val­i­da­tion and return NULL.

This is where getRaw­Cook­ies() comes in:

$cookie = Craft::$app->getRequest()->getRawCookies()
->getValue('user_timezone') ?? null;

Some stuff to help you along during the lesson: