• So coldforged help me get the basics working. Thanks so much! However, while this seems to be working ok most of the time, when I try to look at a post, the cookie I am writing to is reset to default. I have posted the code below. Any thoughts would be great.

    A little note, inorder to load different themes, and different colors for each theme, I use the folowing to set the theme dir, the color dir of that theme, and the font size.

    Let me know. Thanks.

    //This Controls Theme Choice
    if (isset($_GET['theme'])){
    setcookie ('styletheme', $_GET['theme'], time()+31536000, '/', 'localhost', '0');
    $theme = $_GET['theme'];
    } elseif (isset($_COOKIE['styletheme'])) {
    $theme=$_COOKIE['styletheme'];
    } else {
    setcookie ('styletheme', 'beach', time()+31536000, '/', 'localhost', '0');
    $theme = 'beach';
    }

    //This Controls Color
    if (isset($_GET['color'])){
    setcookie ('stylecolor', $_GET['color'], time()+31536000, '/', 'localhost', '0');
    $color = $_GET['color'];
    } elseif (isset($_COOKIE['stylecolor'])) {
    $color=$_COOKIE['stylecolor'];
    } else {
    setcookie ('stylecolor', 'color-1', time()+31536000, '/', 'localhost', '0');
    $color = 'color-1';
    }

    //This Controls Font Size
    if (isset($_GET['set'])){
    setcookie ('sitestyle', $_GET['set'], time()+31536000, '/', 'localhost', '0');
    $sitestyle = $_GET['set'];
    }
    else if (isset($_COOKIE['sitestyle'])) {
    $sitestyle=$_COOKIE['sitestyle'];
    } else {
    setcookie ('sitestyle', 'small', time()+31536000, '/', 'localhost', '0');
    $sitestyle = 'small';
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • It’s because you’re setting an explicit path. Therefore, every subdirectory on your site will get it’s own cookie. Bleh. Remove the parameters to setcookie() after the expiration time.

    Thread Starter dave_merwin

    (@dave_merwin)

    Wow. Thank you so much. My favorite part is the “bleh”. LOL. You were right. Thanks.

    ??

    ColdForged, I have a similar problem. Simplifying the setcookie code didn’t work for me.

    According to the setcookie manual: “If [the path is] set to ‘/’, the cookie will be available within the entire domain.” https://us3.php.net/setcookie

    So something like this should work, no?

    setcookie(“name”, “value”, time()+3600*24*30, “/”, “.domain.net”, 0);

    But my code, when included from a wp page, doesn’t get the cookie value. (It does detect the cookie through the isset function though.)

    I tried these two changes, which didn’t seem to work either:

    setcookie(“name”, “value, time()+3600*24*30);

    and

    setcookie(“name”, “value”, time()+3600*24*30, “/”, “.domain.net”, 0);
    setcookie(“name”, “value”, time()+3600*24*30, “/blog”, “.domain.net”, 0);

    Any ideas?

    My guess is that Dave’s problem was more with the “localhost” part of his call than the “/” part.

    EDIT: On second thought, that doesn’t make sense.

    Ok. I’ve got it working for me. It seems like the problem was on the retreaval of the cookie, not the setting of it. I changed this line:

    $c_password = $HTTP_COOKIE_VARS[“Winelog_Password”];

    to

    $c_password = $_COOKIE[“Winelog_Password”];

    ideadude…
    it is beneficial to look at the DATE of posts/topics you are posting to.
    In April 2005 (!) there was a totally different WP version.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘More on Setting Cookie in Head’ is closed to new replies.