Title: Disable caching if session variable exists
Last modified: March 1, 2022

---

# Disable caching if session variable exists

 *  Resolved [katmacau](https://wordpress.org/support/users/katmacau/)
 * (@katmacau)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/disable-caching-if-session-variable-exists/)
 * Hello. I have some content that appears based on if a session variable has been
   set. For example, if they are a repeat viewer (have a session var stored) then
   a header strip appears. The problem is that hummingbird is caching the pages 
   without the header strip.
 * I need it show the header strip if the session variable is set. I know you can
   do things with cookies and logged in status. but how to I get it to no cache 
   pages if session var set?
 * Can I just put this into my header.php in the theme to dynamically set cache 
   status for all pages?
 *     ```
       <?php if(is_user_logged_in() || isset($_SESSION['repeat_viewer']) {
       define('DONOTCACHEPAGE', true); } ?>
       ```
   
 * Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Kris – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport13/)
 * (@wpmudevsupport13)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/disable-caching-if-session-variable-exists/#post-15414508)
 * Hi [@katmacau](https://wordpress.org/support/users/katmacau/)
 * I hope you are doing good today.
 * We do not have any feature yet, which will allow o not to cache specific parts
   on the page. The only way in those cases will be, for now, to use iframe, which
   loads content from a different page that is not cached.
 * Kind Regards,
    Kris
 *  Thread Starter [katmacau](https://wordpress.org/support/users/katmacau/)
 * (@katmacau)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/disable-caching-if-session-variable-exists/#post-15416750)
 * Thanks. But it was more I dont want the entire page to be cached when that session
   var is set. So general public see cached pages, those who are wordpress logged
   in OR those who have that session variable set I want them to see non-cached 
   pages.
 * Is that possible? On an entire page level?
 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/disable-caching-if-session-variable-exists/#post-15422956)
 * Hi [@katmacau](https://wordpress.org/support/users/katmacau/)
 * For the entire page, your code should work yes.
 * I just tested on my lab site by using
 * `[2022-03-03T14:56:39+00:00] Page not cached because DONOTCACHEPAGE is defined.`
 *     ```
       session_start();
   
       $_SESSION["repeat_viewer"]='just a test';
   
       if( isset( $_SESSION['repeat_viewer'] ) ) {
       define('DONOTCACHEPAGE', true); }
       ?>
       ```
   
 * And it prevents the cache as expected.
 * Just some important notes, by default, Hummingbird won’t cache logged-in users,
   unless you enable it in Hummingbird settings, if you don’t enable it the code
   is not necessary.
 * On your code is missing an extra )
 *     ```
       <?php if( is_user_logged_in() || isset( $_SESSION['repeat_viewer'] ) ) {
       define('DONOTCACHEPAGE', true); } ?>
       ```
   
 * Best Regards
    Patrick Freitas
 *  Plugin Support [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * (@wpmudev-support2)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/disable-caching-if-session-variable-exists/#post-15475826)
 * Hello [@katmacau](https://wordpress.org/support/users/katmacau/) ,
 * We haven’t heard from you for some time now, so it looks like you don’t need 
   our assistance anymore.
 * Feel free to re-open this ticket if needed.
 * Kind regards
    Kasia

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Disable caching if session variable exists’ is closed to new replies.

 * ![](https://ps.w.org/hummingbird-performance/assets/icon-256x256.gif?rev=2633221)
 * [Hummingbird Performance - Cache & Page Speed Optimization for Core Web Vitals | Critical CSS | Minify CSS | Defer CSS Javascript | CDN](https://wordpress.org/plugins/hummingbird-performance/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/hummingbird-performance/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/hummingbird-performance/)
 * [Active Topics](https://wordpress.org/support/plugin/hummingbird-performance/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/hummingbird-performance/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/hummingbird-performance/reviews/)

 * 4 replies
 * 4 participants
 * Last reply from: [Amin – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support2/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/disable-caching-if-session-variable-exists/#post-15475826)
 * Status: resolved