[Plugin: WP Super Cache] Logged in but actually not
-
Hi, I’ve recently gotten my WordPress blog up and running and I’ve been wondering it there’s anyway to keep WP-Super-Cache from displaying me as logged in when I’m actually not short of returning to dynamic pages. The problem is that when I log out on a page, the appearance of the page remains the same as if I were actually logged in.
Any help would be appreciated. ^^
Thanks for your time.
-
I’ve finished writing and testing the WP Super Cache plugin. So far over 3000 pages have been cached on the production sites and none of them show the logged in view, which is good news. The cookie to test for was of the form “fbc_<facebookAppID>” and I used the wp_cache_get_cookies_values hook to add it.
Leirith, could you summarize your findings/solution? It sounds like your issue involved detecting a facebook plugin cookie? How did you narrow that down and what/where is the connection with WP Super Cache?
I’m still having this issue as I reported earlier and had taken a break from debugging it. I’m not using the facebook plugin though, but perhaps it could also be cookie related? I’ll have to have a look at the function in wp-cache-phase1.php that checks the COOKIE array.
Hi dspilka,
Initially I suspected the issue was purely related to the facebook plugin, but I then noticed the issue was reproducible for specific URLs on the site. I thought about how pages were being cached by WP Super Cache and discovered that the logged in view was being cached by WP Super Cache by searching in the supercache directory for files containing strings from the logged in view.
I then wondered if the issue was related purely to WP Super Cache but I made a test installation without the facebook plugin and the issue wasn’t occurring – so I installed the facebook plugin and the issue was back.
I set about looking at how WP Super Cache was determining whether or not a user was logged in and found the function in wp-cache-phase1.php, there is a function called wp_cache_get_cookies_values(). It looks for three different cookie keys that WordPress sets when a user is logged in. I stepped through the code and found that when a user was logging in with facebook, those cookies were not being set right away. There was however a cookie that was being set at this stage, which was of the form fbs_<facebookAppID>.
I found an article that described similar issues with a facebook plugin and WP Super Cache, and in that case it was solved by writing a plugin for WP Super Cache to check for an additional cookie key. The cookie key was different to the one my facebook plugin was setting, so I adapted the code from wp_cache_get_cookies_values() in wp-cache-phase1.php, added it to a plugin which hooks to wp_cache_get_cookies_values and placed it in the WP Super Cache plugins directory. Additionally, as a comment in wp_cache_get_cookies_values() suggested, I added the cookie to test for to the conditions in the .htaccess file in the WordPress root directory.
Here’s the code for the plugin.
<?php function fbconnect_patch_get_cookies_values($string) { if (!isset($string)) $string = ''; while ($key = key($_COOKIE)) { if ( preg_match( "/^fbs_/", $key ) ) { if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "Cookie detected: $key", 5 ); $string .= $_COOKIE[ $key ] . ","; } next($_COOKIE); } reset($_COOKIE); return $string; } add_cacheaction('wp_cache_get_cookies_values', 'fbconnect_patch_get_cookies_values'); ?>
Below is the line that I altered in .htaccess. It occurs twice in this file. As you can see I added the cookie prefix “fbs_” to the regular expression.
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_|fbs_).*$
Leirith – thanks for posting such a detailed response. Hopefully it’ll help authors make their plugins compatible.
Instead of editing the .htaccess you could use the “supercacherewriteconditions” filter to add the “fbs_” cookie fragment to the rewrite_rules. Look for the filter in wp-cache.php and you’ll see the rules are passed to it in one big string (lines separated by carriage returns)
Thanks Leirith,
Could you just explain, please, the steps to create this plugin.
DO I just create a php file in the wp-content/plugins/wp-super-cache/plugins folder ?
with the above code in it?
What should I call the file or is it up to me?
I did these steps but there is no plugin showing on the wp supercache plugins page in settings.
Did I miss a step?
Many thanks
Hi Pete,
Yes, create the PHP file in the wp-content/plugins/wp-super-cache/plugins folder with the code I posted. You can call the file anything you like.
Don’t worry about it not showing up in the admin screen – it will still execute. I’m not sure how to add it to the admin screen actually. I can see there is a file that lists the other plugins but I haven’t found any documentation for how to modify it. Perhaps it’s something that donncha can clarify.
I also added a filter for the rewrite rules as suggested by donncha. This code went in the same file.
function fbconnect_patch_supercacherewriteconditions($condition_rules) { $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*fbs_.*$"; return $condition_rules; } function fbconnect_patch_filters() { add_filter('supercacherewriteconditions', 'fbconnect_patch_supercacherewriteconditions'); } add_cacheaction( 'add_cacheaction', 'fbconnect_patch_filters' );
Hope this helps.
HI, I can’t say that this is working either. If I log out, all other links are showing as logged out, except the home page!
I even deleted the facebook like plugin.
Can you suggest a troubleshooting procedure? I do appreciate your help. Having got allthe CDN stuff working with cnames, I feel I am so close to geting the sites running at the speed and functionality that I want.
DO I still need to replace those htaccess lines?
Check the readme.txt for the troubleshooting tips there, but the debug log the cache plugin generates will tell you loads. Also examine the cached files in the wp-content/cache/ directory. Look in wp-content/cache/supercache/ too. Are they logged in or out cached files?
Thanks Donncha,
The gzip file and normal cache file for homepage are the logged in versions.
When I view source on a logged out home page, I still see the logged in page, and there is no supercache stamp at the bottom of the source.
Debug on a hompage request followed by logout caused the following..
17:13:31 / wp_cache_shutdown_callback: collecting meta data.<br /> 17:13:37 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd Cookie detected: wordpress_logged_in_6818ee256090c441ae0383ba20094c89<br /> 17:13:37 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd supercache dir: /home/sites/peteluxford.com/public_html/wp-content/cache/supercache/www.peteluxford.com/wp-login.php/<br /> 17:13:37 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd No wp-cache file exists. Must generate a new one.<br /> 17:13:39 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd Cookie detected: wordpress_logged_in_6818ee256090c441ae0383ba20094c89<br /> 17:13:39 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd In WP Cache Phase 2<br /> 17:13:39 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd Setting up WordPress actions</p> <p><br />17:13:39 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd Supercache caching disabled. Only using wp-cache. Non empty GET request.<br /> 17:13:39 /wp-login.php?action=logout&redirect_to=peteluxford.com&_wpnonce=89f80ea9cd URI rejected. Not Caching</p><br /> <p>17:13:40 /peteluxford.com supercache dir: /home/sites/peteluxford.com/public_html/wp-content/cache/supercache/www.peteluxford.com/peteluxford.com/<br /> 17:13:40 /peteluxford.com No wp-cache file exists. Must generate a new one.<br /> 17:13:41 /peteluxford.com In WP Cache Phase 2<br /> 17:13:41 /peteluxford.com Setting up WordPress actions<br /> 17:13:41 /peteluxford.com Created output buffer<br /> 17:13:41 /peteluxford.com Output buffer callback</p> <p><br />17:13:41 /peteluxford.com Buffer is blank. Output buffer may have been corrupted by another plugin or this is a redirected URL. Look for text 'ob_start' in the files of your plugins directory.<br /> 17:13:41 /peteluxford.com No closing html tag. Not caching.<br /></p> <p>17:13:41 /peteluxford.com wp_cache_shutdown_callback: collecting meta data.<br /> 17:15:50 /wp-admin/admin-ajax.php In WP Cache Phase 2<br /> 17:15:50 /wp-admin/admin-ajax.php Setting up WordPress actions<br />
Is that the problem in bold?
I have found that as soon as I clear my Browser cache and refresh the page in question it immediately loads the supercache file.
Is there a way to stop my browser caching just my site?
I had the exact same problem. It was caching me as logged in. After reading this I figured it is related to the comments form.
Maybe you want to create a list of plugins that are incompatible?
Here’s the one that does not work for whatever reason:
– growmap-anti-spambot-pluginOther problems I found recently
When you deactive Superache 0.9.9.9 and get the message you need to remove WP_CACHE it will display that message even after removing it. Strange!Another problem, the entire site breaks when you have an invalid wp-cache-config.php or if you copy the sample config into wp-content. Could be fixed in 1.0?
And another problem is the mfunc tag does not always work with Late-Init in 0.9.9.9 .. but I need to look into it don’t know how to reproduce the bug.
Pete_PT – check the cacheability of your site using https://redbot.org/ – that will tell you how anonymous browsers see your site.
You could try editing wp-content/cache/.htaccess and changing the “max-age” to 0 or a smaller number than the default 300.
sOliver – it’s probably better if you post a message to that plugin’s forum saying the plugin isn’t compatible with supercaching. Hopefully the author will fix it if possible. If it doesn’t work with this caching plugin it probably won’t work with others.
The WP_CACHE warning is I think because the wp-config.php on your server wasn’t writeable. Thanks.
What error did you see when you tried to use the sample config file? Unfortunately the config file is loaded by every page served so if it’s broken then the site will break. Did the plugin break it or were you editing it by hand?
Again thank you.
HTTP/1.1 200 OK Date: Fri, 11 Mar 2011 08:09:46 GMT Server: Apache/2 Last-Modified: Thu, 10 Mar 2011 14:40:59 GMT Accept-Ranges: bytes Content-Length: 8563 Cache-Control: private, pre-check=0, post-check=0, max-age=0 Expires: 0 Vary: Accept-Encoding,Cookie Pragma: no-cache Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 Content-Encoding: gzip
It’s still cacheing in my browser though. Have to say this is driving me mental ?? When I log in, it only seems to cache some of the logged in pages. So when I log out, some pages are logged in versions others aren’t!
Am going to disable all plugins again and re-activate one by one again, using two computers to see what is caching externally.
I have experienced a similar problem to that described by Lunarll and dspilka, and I believe I understand some aspects of what is happening.
For clarity, I don’t think my problems is similar to Leirith’s. I am not using a facebook plugin – rather I simply call is_user_logged_in() to select a welcome message and menu.
Under FireFox I get the logged in message even after I have logged out. The reason is that it is still in the browser cache. Under IE the problem did not appear. It comes down to how these browsers are responding to 304 messages.
I’m not entirely sure how FireFox is treating the 304 and associated cookies, but that’s where the problem lies. By deactivating the WP Super Cache use of 304 messages, both browsers behave in the expected way.
This problem was a real concern for a while, so I hope this helps.
- The topic ‘[Plugin: WP Super Cache] Logged in but actually not’ is closed to new replies.