1

I have a module that implements a hook_boot(), and it checks if user is going to access home page and if user does not have a specific cookie. If both verifications are true, it redirects user to a /welcome page and set cookie. So the second time a user tries to access home page, it will see that user has the cookie and will not redirect.

Recently, I installed Varnish on my site, and everytime I try to access home page, I get to /welcome page. It never skips.

I'm not sure but it looks like the first time I access home page, when I still don't have cookie, it caches the home page, shows /welcome page and set cookie. Then, second time I try to access home, it gets the cached page (which thinks I don't have cookie) and redirect again to /welcome page, even though I have cookie.

I tried not caching home page but it didn't work.

Any thoughts?

2

If you use Varnish - you must consider that for anonymous users PHP code will not execute at all - they will retrieve only static HTML.

In you case solution can be as following:

  1. On welcome page set cookie by JavaScript not PHP.
  2. Using Varnish vcl script check if user loads homepage and has cookie. If not - then redirect it to welcome page.

Now item #2 is made in PHP code but you need rewrite it using Varnish. You can also write item #2 using JavaScript but it will work much slower and user will see browser redirection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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