Best way to use saveCookie and craft.request.getCookie('location') Following up on this question: Prescribed way to set cookies (from plugin or Twig) the following works great.

craft()-&gt;userSession-&gt;saveCookie($cookieName, $data, $duration);


I can see Location being set as my cookie in the Application Log but when I try to use {{ craft.request.getCookie('location') }} It returns blank.

What am I missing here?

Edit - Upon closer inspection it doesn't look like saveCookie is working correctly either. I see location from when I was using setFlash but I need the data to persist even if the page is reloaded.
You should probably be using something like this:

    $cookie = new HttpCookie($name, $value);
    $cookie-&gt;expire = time() + 3600;

    craft()-&gt;request-&gt;getCookies()-&gt;add($cookie-&gt;name, $cookie);


Setting whatever properties you want on HttpCookie.

Using UserSessionService->saveCookie is meant mainly for Craft's session identity cookie, so it has some security checks it goes through saving the cookie that craft.request.getCookie('location') is probably failing.