tags:

views:

285

answers:

2

I'm using a very simple Stylesheet Switch by php. It was fine all along but days ago I turn on Caching mode and now it only work for login user. If turn off Caching mode, it will work again for both user.

Basically the code looks like this

In the page.php header

  <?php
    if(isset($_COOKIE['style'])){
      $style=$_COOKIE['style'];
    } else {
      $style='green';
    }
  ?>
  <link type="text/css" rel="stylesheet" href="/css/<?php echo $style ?>.css">

It switch by

<a href="http://www.mydomain.com/switch.php?style=blue"&gt;Blue&lt;/a&gt;

In the switch.php

<?php setcookie('style', $_GET['style'], time()+31536000);
header('Location:'.$HTTP_SERVER_VARS['HTTP_REFERER']);
?>

I did many research but couldn't find the right way. Please help if you can. Thank you

+2  A: 

Hmm, I don't see why you can't just use a client-side style switcher, as in http://www.alistapart.com/articles/alternate/. There are other methods of doing it purely client-side, but it seems a bit overkill to request an entire new page to switch styles.

Also, caching creates a static page to serve up in lieu of dynamically creating a new page for every hit, so the cached page is probably getting served up to whoever isn't getting the style switching.

thenoviceoof
Thank you very much for respond. I saw the article before. I didn't try it because I want user be able to switch it on the main menu instead of on a page. onclick="setActiveStyleSheet('') seems bit hard to implement on primary menu list. May be I should just give up my preference on this. You are right, client-side switcher might be my only option if I turn the Cache mode on.
mesmer
+1 - Enabled caching will pretty much 'disable' any custom php code that would alter a page served for a specific URL, as the page will indeed be served as a 'static' version taken directly from the cache tables. So a client side solution would be the obvious workaround.
Henrik Opel
A: 

From my understanding/experience standard drupal caching is only for non-logged in users. There is at least one module that allows for authenticated user caching, but it's not in Core, authcache: http://drupal.org/project/authcache

An old article that explains druapl caching techniques. Still has some good information in there: http://n0tablog.wordpress.com/2007/11/19/drupal-caching/

easement

related questions