• I have a simple setcookie and redirect code that works fine for logged in users (who aren’t cached) but it doesn’t work for non-logged in users (who are cached). W3 Total Cache is conflicting with this code, and even when I tell W3 Total cache not to cache header.php it still doesn’t work.

    <?php
    if(is_front_page() )
    {
    if( !(isset($_COOKIE[‘sitecookie’])) )
    {
    header(“location: /popular”);
    }
    }
    ?>

    <?php
    if(is_front_page())
    {
    setcookie(“sitecookie”, “CookieValue”, time()+10368000);
    }
    ?>

    What’s weird is a similar version of this code was previously working even with W3 Total Cache turned on, but I made some changes to the site so I needed to adjust the code and now even if I tried putting the old code back in, the setcookie and redirect no longer work.

Viewing 3 replies - 1 through 3 (of 3 total)
  • +1 need to know about this

    @SgrWd, did you find a solution?

    I see a problem with your code:
    <?php
    __the code__
    ?>

    <- blank = output!

    <?php
    __the code__
    setcookie();
    ?>
    There should’t be any output before calling setcookie! Have you tried this:

    <?php
    __the code__

    __the code__

    setcookie();
    ?>

    You’ll need to make sure the cookie is rejected in the page cache settings.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Setcookie/php-redirection conflicting with W3 Total Cache’ is closed to new replies.