[wp-hackers] Handling cookies with wp-plugin and wp-supercache

Gerrit Wessendorf celeph at gmail.com
Sun Nov 1 18:24:11 UTC 2009

I hope this isn't too offtopic, but I was hoping someone might be able to
give me a hint or idea. :)

The situation:
I wrote a simple plugin for wordpress that reads the http-referrer and sets
a cookie with info about searchengine or email referrals. This cookie is
available in the entire session until the user closes the browser. The value
can be used with a function in template files, or shortcodes in pages/posts.
With Firefox plugin refspoof I simulate different referrers.

This all works great both as wp-plugin and outside of wordpress as included

I installed wp-supercache, added my cookiename to supercache's rewrite rules
in .htaccess,

RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie}

and I used the following for my test markup:

<!-- mfunc AgoraCapture::html() -->
<?php AgoraCapture::html(); ?>
<!-- /mfunc-->

The function html() returns some html markup with to display the value(s)
and a link to remove the cookie.

I also defined some shortcodes which work great without supercache and still
need to be tested with supercache, once I get the html() test working.

The problem:
My test function doesn't seem to be able to update or delete the cookie once
wp-supercache is activated. If I visit the site by typing in the url
directly, my code will set a value indicating it's a direct visit. If I then
choose to remove and spoof a new referrer the directvisit-value stays and
remains unchanged. If I manually delete the cookie from the browser's cookie
list I'm able to simulate another referrer, but once the cookie is set, it
stays there until I manually remove it again. This makes it a bit difficult
to test different scenarios, and I'm not able to tell if the site would set
the proper values in a real-world situation.

I have the feeling it might just be a minor detail I have overlooked, and I
can't imagine I'm the first to handle cookies in a wp-supercache
environment. Have you ever developed a plugin or wordpress extension that
handles cookies and had to work with wp-supercache?

Any hint is really appreciated.
Many thanks in advance,

More information about the wp-hackers mailing list