• I have been writing cookies in order to store and test layout tweaks for each user, but WP Super Cache seems to be causing major issues. WP Super Cache is using the cached value of the cookie, even if the cookie has been rewritten or deleted. It is even using that cached value across other users’ computers!

    Everything works fine on client-side Javascript, but the issue happens when reading the cookie via PHP. When I disable WP Super Cache, it also works perfectly. I need to be able to read the cookie value on server-side so I can make dynamic adjustments before the HTML is output.

    Is there any way to exclude specific cookies from being cached entirely?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Look in wp-cache-phase1.php at the wp_cache_get_cookies_values() function. There’s a “cache_action” there called “wp_cache_get_cookies_values” that you can use as a filter to modify the cookie used to cache the page with. You can probably add your cookie to that string.

    You’ll have to add this function as a Supercache plugin so it loads really early in the WordPress process.

    Thread Starter froppitmf

    (@froppitmf)

    Donncha, thanks very much for the help! Unfortunately I can’t seem to get this to work. I tried creating a custom function in wp-cache-phase1.php with the ‘wp_cache_get_cookies_values’ but I think I am using it incorrectly:

    function get_the_src() {
    $cook = $_COOKIE[‘cookiename’];
    $str = do_cacheaction( ‘wp_cache_get_cookies_values’, $cook );
    return $str;
    }

    I’m having the same problem, where it is retrieving the cookie value that is stored in the cache — not the updated cookie values.

    It does not seem like there is any way to assign the cookie to a PHP variable before the Supercache plugin loads. It is very frustrating, as a lot of my PHP is rendered useless without being able to read the cookies properly for each user.

    I am not a very experienced with WP, so I apologize if this is not what you were suggesting. Any further assistance would be greatly appreciated.

    • This reply was modified 7 years, 5 months ago by froppitmf.

    Hi @froppitmf

    I have the same problem using WP Super Cache. Did you find a solution working with cookies and WP Super cache?

    @donncha, Could you post here an example please? Sorry but I didn’t understand your reply.

    Thank you.

    • This reply was modified 7 years, 3 months ago by raualvron.

    Take a look at the plugins/searchengine.php file. Once you start adding to the list of cookies those pages will be stored as wp-cache files with the cookie used in the key to identify the cached file.

    RFC2109:

    “If the cookie is intended for use by a single user, the Set-cookie
    header should not be cached. A Set-cookie header that is intended to
    be shared by multiple users may be cached.”

    How does WP Super Cache handle nonces? Does it serve up the same nonces to all its visitors during the cache lifetime?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Cookie issues with WP Super Cache’ is closed to new replies.