*

webcity

  • *****
  • 252 posts
Cloudflare cache all for visitors
« on: December 18, 2023, 09:19:29 AM »
Hi,

I was looking to use the Cloudflare "Cache All" option for non logged-in visitors to speed-up the delivery of pages to visitors.

In the Cloudflare cache options you can configure what pages you want to cache depending on the cookie.

I can't see any cookie that is set just for logged-in users or logged-in administrators, I can see the osclass cookie but this shows for users when logged in or out.

Is there a way to set a cookie that shows when a user is logged-in only?

Many thanks

*

MB Themes

Re: Cloudflare cache all for visitors
« Reply #1 on: December 18, 2023, 10:12:24 AM »
Logged in user will have userId or email in cookies, if "remember me" was checked on login.
Otherwise all data are in session only.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

webcity

  • *****
  • 252 posts
Re: Cloudflare cache all for visitors
« Reply #2 on: December 18, 2023, 11:06:05 AM »
Hi,

Thanks for reply and help.

Could you suggest any code to use to set a new cookie when logged-in only?

I'm sure a lot of Osclass users would find the extra speed from using the free Cloudflare "Cache All" service beneficial. I have used the service on a forum that I have and it makes the site fly for visitors and helps with SEO too, as the pages load fast as they are delivered direct by Cloudflare.

Many thanks

*

MB Themes

Re: Cloudflare cache all for visitors
« Reply #3 on: December 18, 2023, 04:23:54 PM »
Well simplest option is to check in init hook if user is logged.
If yes, add cookie, if no then drop cookie
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

krallen

  • ***
  • 37 posts
Re: Cloudflare cache all for visitors
« Reply #4 on: July 22, 2024, 07:29:52 PM »
I need this too.
Non-logged-in visitors should see Cloudflare Cache All pages.

If logged in members do not have a cache page, cache pages will not appear when entering new ads or messaging on the site, if they are logged in.

how can I do that.

*

MB Themes

Re: Cloudflare cache all for visitors
« Reply #5 on: July 23, 2024, 02:02:53 PM »
@webcity
You can add these codes ie to theme functions.php.
On login, there is hook after_login
Code: [Select]
osc_add_hook('after_login', function() {
  setcookie('user_logged', 1, time() + (86400 * 30 * 12), "/");
});

So you can identify if user is logged using cookie user_logged


On logout, there is hook logout

Code: [Select]
osc_add_hook('logout', function() {
  unset($_COOKIE['user_logged']);
  setcookie('user_logged', '', -1, '/');
});
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots