I recently inherited a Drupal 6 website that is using $_SESSION to store a lot of anonymous user data. Currently none of this $_SESSION data can be accessed while caching is enabled.

I have considered using cookies to work around this limitation but would like a fallback for users without javascript enabled.

Is there a way to do this in D6, D7 or the upcoming D8?

  • What is stored in the $_SESSION data? Knowing the purpose of that data, we can give you better recommendations. Is it stats, user recommendations, user selections, shopping cart, etc. D6 Pressflow, D7, D8 is actually worse in this case, it won't cache the page if any $_SESSION data is set.
    – mikeytown2
    Jul 3, 2012 at 19:31
  • Its actually a vanilla 6.19 install right now. Currently we are using $_SESSION to store data for a registration form. Its a bit lengthy and we use the $_SESSION data to store an auth code that is referenced to call some custom css depending on what code they use.
    – Cluke009
    Jul 10, 2012 at 19:13
  • Session by it's very nature is a storage per session. What would caching it mean? What it's supposed to accomplish? When page is cached, it is put together and stored with exactly the purpose of not regenerating it. So changes in $_CACHE are meant to not affect output. If you want to affect output, cache should be disabled. Long story short - this question is unclear, and should be (probably was) asked again with specific data / situation in mind.
    – Mołot
    Oct 8, 2013 at 11:40

2 Answers 2


I think your best option is to use 2 cookies. Set one cookie that checks to see if the browser has JavaScript enabled. If JavaScript cookie is not there, the user gets an uncached page. If JavaScript does exist then drop a cookie containing the session data. Do the uncached page check in your settings.php file.

If you have something like Varnish or Nginx on your web stack, checkout ESI as it can work how you want it if the browser doesn't support JavaScript.

Also checkout http://drupal.org/project/authcache as it might be what you're looking for (minus the JS part...)

  • This is a pretty good idea. I will definitely check out ESI as it seems to address the problem without having to re-engineer the code and still provides caching.
    – Cluke009
    Jul 13, 2012 at 0:48

If you are having issues with creating the session for anonymous user, then it can be the issue with missing the user whose user ID is zero (anonymous user) from the users table.

You can restore it by running this SQL query from PHPMyAdmin.

insert into users (name, pass, mail, theme, signature, language, init, timezone) values ('', '', '', '', '', '', '', '');
update users set uid = 0 where name = '';

Drupal 7 always need a user with that user ID to create a session for it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.