Drupal Cache & Stylesheet Switch
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">Blue</a>
In the switch.php
<?php setcookie('style', $_GET['style'], time()+31536000);
开发者_如何学Pythonheader('Location:'.$HTTP_SERVER_VARS['HTTP_REFERER']);
?>
I did many research but couldn't find the right way. Please help if you can. Thank you
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.
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/
精彩评论