Xenforo issues with different styles shown for guests

#1
My forum has two theme options: default theme (light in colour) and Shades of grey (dark theme). I am noticing that some pages are being shown in dark theme to guests, others in light theme.

How can I stop this?
 

serpent_driver

Well-Known Member
#2
Set a cookie for users who login and define a vary cache rule in .htaccess:

Example:

Code:
RewriteCond %{HTTP_COOKIE} "loggedin" [NC]
RewriteRule .* - [E=Cache-Control:vary=loggedin_user]
 

serpent_driver

Well-Known Member
#5
Setting a cookie to logged in users is not enough. This cookie must be binded to login status, so if logged in users logoff this cookie must be removed. Otherwise cookie still exists if users logoff and they will get wrong theme.
 
#6
That is not my experience. I have dark theme when logged in. When I log out, I get light theme. So all that works as expected already. I am using the recommended htaccess code as follows:

# LiteSpeed XenForo cache
<IfModule litespeed>
CacheLookup public on
RewriteEngine On
# cache
RewriteCond %{HTTP_COOKIE} !(xf_lscxf_logged_in|xf_user|xf_session_admin) [NC]
RewriteCond %{REQUEST_URI} !/install/ [NC]
RewriteRule .* - [E=Cache-Control:max-age=360]
# no cache
RewriteCond %{HTTP_COOKIE} (xf_lscxf_logged_in|xf_user|xf_session_admin) [NC]
RewriteRule .* - [E=Cache-Control:vary=loggedin,E=Cache-Control:no-cache]
</IfModule>
Yet guests are sometimes seeing dark theme. Or have I misunderstood what you are saying?
 

serpent_driver

Well-Known Member
#7
If guests see the wrong theme, something goes wrong with login cookie if a user logoff. If a user is logging off and login cookie still exists he gets the the theme from logged in user.

Have you manually defined these Rewrite Rules or are these rules defined by the plugin? They don't look okay for me. I would define these rules completely different.
 

serpent_driver

Well-Known Member
#9
In my mind these Rewrite Rules are insufficient for your custom usage. Redis and Cloudflare can make a difference, but it seems to be better to open a support ticket.
 

Michael A

Administrator
Staff member
#10
Howdy @Jon12345 ,

It looks like you've pointed out a regression in our .htaccess rules. We should already be varying on style and language except at some point our rules were updated based on an older ruleset that did not contain these varies.

I'll be updating them shortly on our wiki and will make a post about the updated rules on the official forum.

Thanks,
-Michael
 

serpent_driver

Well-Known Member
#13
To find the reason for this issue, do the following steps:

1.) Logoff from forum
2.) Remove all cookies from your browser and don't request your forum again until all steps are done.
3.) Add the following Rewrite Rule to you .htaccess where all other Litespeed Cache Rules are defined. You can remove this rule after test. This rule prevent file purge.php from beeing cached.
Code:
RewriteCond %{REQUEST_URI} /(purge).php$
RewriteRule .* - [E=Cache-Control:no-cache]
3.)Create a php file with name purge.php without any content.
4.) Paste the following header into this file:
Code:
<?php
header("X-LiteSpeed-Purge: *");
5.) Upload this file to the root directory where your forum is installed.
6.) Run this file in your browser: www.domain.com/purge.php
7.) Open Dev tools in browser (F12) and open network TAB.
8.) Browse a couple of pages of your forum and check cache header of each requested page. Every page should have "miss" header.
9.) Check the cookies in dev tools. If there are cookies with xf_ prefix, post them (name of cookies) here
10.) Browse the same pages again and check cache header of each page. They all should have "hit" header.
11.) Login to your forum as user, not admin.
12.) Browse the same pages as before and check cache header. There should be no cache header. If there is a cache header, post it.
13.) Logged in as user check, if there a cookies with prefix xf_ post them here.
14.) Logoff and login as admin
15.) start with step 11.) and do the same steps as admin
16.) Logoff and check cookies again.
17.) Finished

If finished post your result with cookies. It is important to know which cookie is set at each user status.
 
#14
@serpent_driver Thanks for the suggestion, but isn't it up to litespeed themselves to provide a plugin that doesn't have bugs?

Before, I had the occasional dark page shown. Now, after the new plugin update, all my pages seem to be dark theme. As a result, my bounce rate has gone up, repeat visitors are down, ad revenue is down.

Are the litespeed crew still working on this?
 

serpent_driver

Well-Known Member
#15
The big question is, who has developed this plugin? I don't know much about Litespeed cache plugin for Xenforo, so all I know is that this plugin has only rudimentary cache settings and has to be extended with functions like they are available in other Litespeed cache plugins. You should open a support ticket to get the right answers.
 

Michael A

Administrator
Staff member
#16
Hell again @Jon12345 ,

I've replied to you in our golitespeed slack channel with more details but from my testing while visiting your site everything appears to be working as intended. I could not get it to serve me the wrong theme when switching between themes as a guest.
 

Michael A

Administrator
Staff member
#18
@serpent_driver

This cookie is never used for logged in users, and is actively deleted when changing styles when logged in or when logging out (the style info is stored in the backend somewhere for logged in users instead of a cookie). The cookie IS carried over when logging in, but is ignored for determining style when logged in.

Like-wise if the cookie was for some reason not removed, it would still work as intended as the cookie value would be used in determining the cache vary. So a "dark theme" stlye cookie surviving the login/logout process would result in a "dark theme" version of that page getting cached that would only ever be served to other guests who also have the "dark theme" style cookie value set.

I did notice a csrf complaint when trying to switch styles as a guest while on a page cached by another user - this has been added to my to-do to fix but will not have any affect on the issues talked about here.

Edit: Re-read your message a little more carefully, my bad :oops:. Those cookies will definitely be removed during logoff.
 
Last edited:

Michael A

Administrator
Staff member
#20
No worries at all! Your help is more than welcome, I am just passing along what I know as the lead developer and maintainer for this plugin :)

I always appreciate when members of our community jump in to help one another with issues as they often know best when it comes to actually using our software in the wild. I re-tested login/logout again based on your feedback just to be sure that I wasn't missing anything that could be the issue and luckily did not find anything strange.

As of now I suspect that everything is working as intended but will have to wait for further feedback from @Jon12345 to be sure.

If you are curious, this is the link to our Slack's XenForo channel where I provided more details on what/how I checked Jon's site.

Regards,
-Michael
 
Top