CodeIgniter Forums
cookie library and helpers doesn't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: cookie library and helpers doesn't work (/showthread.php?tid=88978)



cookie library and helpers doesn't work - gabriel_fucci - 12-15-2023

I'm trying to set a cookie to count how many visitors(hits) my posts already have. But the cookie is not sent, what I'm doing wrong?? In my debugging i get "null", or if I try dd($_COOKIE[$cookieName] i get an error.

PHP Code:
if (! has_cookie($cookieName$ipVisitante"__HitPost-")) {
            $cookie = (new Cookie($cookieName))
                ->withValue($ipVisitante)
                ->withPrefix('__HitPost-')
                ->withExpires(new DateTime('+2 hours'))
                ->withPath(current_url())
                ->withDomain(base_url())
                ->withSecure(false)
                ->withHTTPOnly(false)
                ->withSameSite(Cookie::SAMESITE_LAX);

            set_cookie($cookie);
 }

        dd(get_cookie($cookieName), get_cookie("__HitPost-$cookie"), $_COOKIE); 



RE: cookie library and helpers doesn't work - kenjis - 12-15-2023

The following values are invalid.

                ->withPath(current_url())
                ->withDomain(base_url())