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 current projects, which includes adding user-adjusted timezones and times for upcoming livestreams.
He created this functionality using a Craft CMS module in the CraftQuest project, but along the way learned more about how cookies are handled in both Craft CMS and Yii.
We explored when and why you might need to use getRawCookies()
instead of the standard cookie collection — particularly when dealing with JavaScript-set cookies.
When cookies are set via JavaScript, they lack the security signature that Yii applies to server-set cookies. Consequently, these client-side cookies fail Yii’s validation process and become inaccessible through the standard cookies collection. If you try to access a JS-set cookies via getCookies()
, it will fail validation and return NULL
.
This is where getRawCookies() comes in:
$cookie = Craft::$app->getRequest()->getRawCookies()
->getValue('user_timezone') ?? null;
Some stuff to help you along during the lesson: