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

William Canino william.canino at googlemail.com
Sun Nov 1 20:53:32 UTC 2009


> 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.

Plugins/Cookies and Super Cache can work together with a little extra planning.

1. "Full on" super-cached pages -- that is, those served from the
wp-content/cache/sitename/path/index.html -- cannot set, remove or
change cookies directly because the pages are served directly by
Apache and never loaded from WordPress at all.  Alternatives: (1) The
Header directive in Apache or (2) set/remove the cookie in Javascript.

2. "Half on" cached pages can set, remove or change cookies directly
but you have to edit wp-cache-phase1.php -- before line 110 -- because
the pages are served directly by wp-super-cache without running
plugins at all.  See the ff. code.  Alternatives: (1) Load before
Super Cache does or (2) set/remove the cookie in Javascript.

header( 'WP-Super-Cache: WP-Cache' );
// <-- add your Cookie-setting PHP here. Go nuts.
if ( $meta[ 'dynamic' ] ) {
	include($cache_file);
} else {
	readfile( $cache_file );
}
die();

Does this make sense? You may need to state your problem more
succinctly because I don't understand.

W



2009/11/1 Gerrit Wessendorf <celeph at gmail.com>:
> Hi,
> 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
> object.
>
> I installed wp-supercache, added my cookiename to supercache's rewrite rules
> in .htaccess,
>
> [...]
> RewriteCond %{REQUEST_URI} !^.*[^/]$
> RewriteCond %{REQUEST_URI} !^.*//.*$
> RewriteCond %{REQUEST_METHOD} !POST
> RewriteCond %{QUERY_STRING} !.*=.*
> RewriteCond %{HTTP:Cookie}
> !^.*(comment_author_|wordpress_logged_in|wp-postpass_|MYCOOKIENAME).*$
> [...]
>
> 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,
> Gerrit
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list