michnhokn / kirby-cookie-banner

A Cookie Consent Modal for Kirby
MIT License
67 stars 9 forks source link

CookieBanner::getCookie returns NULL even if cookie is readable via $_COOKIE #20

Open mayfinn opened 6 months ago

mayfinn commented 6 months ago

I have a problem reading the cookie via your provided functions. I identified the root problem to be the hashing of cookies in Kirby. The CookieBanner::getCookie returns null because Cookie::get returns null. This is due to the early access in https://github.com/getkirby/kirby/blob/6b7ac66c55ecac20d6b580ef01a667d1806d5c72/src/Http/Cookie.php#L143

anselmh commented 4 months ago

For completeness, here’s a local workaround for those who need it:

private static function getCookie(): ?string
    {
        $cookie = $_COOKIE[self::COOKIE_NAME] ?? null;

        if (!is_string($cookie) or empty($cookie)) {
            return null;
        }
        return $cookie;
    }