Web Analytics Made Easy -
StatCounter Trying to use Cookies with Include() - CodingForum

Announcement

Collapse
No announcement yet.

Trying to use Cookies with Include()

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trying to use Cookies with Include()

    Hello. At the moment, I'm trying to have this file:

    PHP Code:
    <?php
    if ($_COOKIE['slot1'] == 'none')
    {
    $cookiesalreadyset 1;
    } else {
    setcookie ('slot1''none');
    setcookie ('slot2''none');
    setcookie ('slot3''none');
    setcookie ('slot4''none');
    setcookie ('slot5''none');
    setcookie ('slot6''none');
    setcookie ('slot7''none');
    setcookie ('slot8''none');
    setcookie ('slot9''none');
    setcookie ('slot10''none');
    setcookie ('all''none');
    }

    echo (
    'working'); //debugging
    ?>
    Become called on a page using include(). However, on my pages, I get the 'working' text, yet cookies aren't set. I'm calling the function before any HTML. In short, I suppose I'm asking if cookies can be set using an included file, as that can be the only possible cause of this problem I can see at the moment. However, any help would be apprichated. I've looked at the manual, but can't see anything in there to help me.

    --- Luke

  • #2
    You could use only 1 cookie if you'd store an serialized array.
    'working' will always be prinbted becouse it is after the if/else.
    There should be no problem in stting cookies with an included file. You just have to be sure that you have cookies enabled and the cookie domain is correct.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

    Comment


    • #3
      Can you clarlify or provide a link to more infomation about cookie domain please?

      And I should have explained a bit better I supose: the echo is to check that the script is being called in the page I put it in. The thing is, 'testing' appears, yet no cookies at all are set. (I've checked by looking at the list of cookies on my machine in firefox)

      Comment


      • #4
        http://www.php.net/setcookie
        the domain parameter is descripbed and theres a link to cookie specification (if you're interested).
        I'm not sure if this was any help, but I hope it didn't make you stupider.

        Experience is something you get just after you really need it.
        PHP Installation Guide Feedback welcome.

        Comment

        Working...
        X