ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

These cookies don't taste so good...

January 27, 2008 7:39pm

Subscribe [2]
  • #1 / Jan 27, 2008 7:39pm

    DEA

    257 posts

    First off, the PHP code:

    header("Content-Type: text/html; charset=utf-8");
        header("Cache-Control: no-cache, must-revalidate"); // HTTP 1.1
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    
        global $SESS, $DB, $IN, $FNS;
        
        //SET COOKIES
        $segment_2 = $IN->SEGS[2];
        $segment_3 = $IN->SEGS[3];
        $texpire = time()+2592000;
        $FNS->set_cookie("country",$segment_2,$texpire);
        $FNS->set_cookie("city",$segment_3,$texpire);

    This occurs at the very top of the template. PHP is set to ouput. And it all works, with one bug that ruins it all, and that is that the page this codes is on always has to be reloaded for the cookies to be updated. For example, if I visit the page at http://www.domain.com/mypage/oregon/portland, nothing happens. But if I then hit reload, the cookie is properly set. I can’t help but think it’s an odd caching issue (hence the headers being set in PHP at the beginning) but nothing helps.

    FYI, generate page headers is turned on in my config. I’ve tried this with that setting off as well, but no dice.

    Help!

  • #2 / Jan 28, 2008 3:13pm

    e-man

    1816 posts

    This is a long shot, but have you tried adding:

    exit();

    as a last line to that block of php?

  • #3 / Jan 29, 2008 12:08pm

    DEA

    257 posts

    Hey there, figured it out. As I was setting the cookie in PHP, it wasn’t actually creating the cookie client-side until the page was reloaded. Makes sense. I’ve since moved to creating the cookie with Javascript when clicking on a link to the page in question, which is working great.

    Thanks for weighing in!

  • #4 / Feb 01, 2008 12:48am

    DEA

    257 posts

    and….. no good. I’ve now created an embed to output the cookie, but it isn’t working for the custom field search either. Which makes me wonder now… is it not possible to pass anything dynamic to this parameter?!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases