• Hi,

    I’m developing a new plugin and could do with setting a cookie to track if the user has previously visited the site. But I can’t seem to get it working.

    I have read that with wordpress you need to set domain etc in the setcookie() call, but i have tried this and it still doesn’t drop a cookie. I’m even using the built in wordpress COOKIEPATH and COOKIE DOMAIN like so

    $Month = 2592000 + time();
    setcookie("testcookie", "cookievalue", $Month, COOKIEPATH, COOKIE_DOMAIN);

    i put that in a function which is called from a get_header action, so it is set before any html is printed etc. I’ve even tried calling it at wp and init but still with no joy.

    I know WP has a few quirks, like the whole $() javascript thing, so maybe there is some specific way of setting your own cookie for a plugin that i’m missing?

    I hope some one can shed some light on this, i spent pretty much all of yesterday trying to figure it out.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mymoog

    (@mymoog)

    i’ve just tried this on a completely fresh wp install, with no other plugins installed and even added an extra bit to the setcookie() which apparently works, but does nothing for me.
    setcookie("testcookie", "cookievalue", $Month, COOKIEPATH, COOKIE_DOMAIN,false,true);
    Does anyone have any ideas?

    I was having the exact same difficulty. But thanks to your post, I tried using the variables for the path and domain, but I also added false as the last argument.

    setcookie(‘name’, ‘value’, time()+3600, COOKIEPATH, COOKIE_DOMAIN, false);

    worked for me called via

    add_action(‘init’, ‘writecookies’);

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘wordpress and setcookie()’ is closed to new replies.