[wp-hackers] WP 2.6.3 and setcookie

Dougal Campbell dougal at gunters.org
Fri Nov 7 17:35:09 GMT 2008

Claudio Simeone wrote:
> HI all,
> I can't set cookies in WP 2.6.3 in a plugin. I'm using:
> setcookie('read'.$post_ID, 1, time() + 86400, COOKIEPATH, COOKIE_DOMAIN);
> The plugin count hits to single posts and set a cookie for each post
> to exclude visits from the same user for one day after the first hit.
> It seems that there's something that resets the all COOKIE values
> (except the WP ones) - because refreshing one single post several
> times, randomly, the cookie is set sometimes, but when I refresh again
> the cookie is not more set.
> Any ideas?

If you are just refreshing your browser without clearing the cache, then 
WordPress might be returning a 304 NOT CHANGED response, in which case, 
it wouldn't be re-sending the set cookie headers.

Try either clearing your browser cache between refreshes, or use a 
command-line tool like curl to examine the headers:

  curl --head http://example.com

Dougal Campbell <dougal at gunters.org <mailto:dougal at gunters.org>>

More information about the wp-hackers mailing list