WordPress.org

Ready to get started?Download WordPress

Forums

Page specific cookies (5 posts)

  1. shua
    Member
    Posted 7 years ago #

    I would like to set a cookie when which read back will kick off some conditional code.

    setcookie() must be declared prior to <html> and <body>

    The issue I am coming up against is that the Page Template declaration must be the first thing on the template. And therefore, header information has already been sent to the browser.

    How should I go about coding this?

    cheers!

  2. shua
    Member
    Posted 7 years ago #

    ok, I placed my code in the header.php and do a is_page() to set the cookie.

    still when I try to read it back I continually get a 'false' read rather than a 'true'.

    thoughts?

    error msg: PHP Warning: Cannot modify header information - headers already sent...

  3. moshu
    Member
    Posted 7 years ago #

    Just put the error message in the search box...

  4. shua
    Member
    Posted 7 years ago #

    ok. that didnt help, but I seem to have fixed the error.

    Now there is no error, but the cookie is not being set.

    my code (in first line of header.php):

    <?php if(is_page(139)){
    setcookie ("canDownload", "yes", time()+60*60*24*365*5);
    }
    ?>

  5. shua
    Member
    Posted 7 years ago #

    solution: used dojo

    super easy.


    dojo.require("dojo.io");
    dojo.io.cookie.set("canDownload","yes",365);

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags