1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Cookie Array

Discussion in 'PHP' started by domokun, Feb 13, 2009.

  1. #1
    Might be an obvious answer but I can't get my head 'round it.

    Here's my Cookie Array

    <?php
    setcookie("cookie[three]","cookiethree");
    setcookie("cookie[two]","cookietwo");
    setcookie("cookie[one]","cookieone");
    
    ?>
    Code (markup):
    Heres the way to show all values within the Cookie Array

    <?php
    
    // print cookies (after reloading page)
    if (isset($_COOKIE["cookie"]))
      {
      foreach ($_COOKIE["cookie"] as $name => $value)
        {
        echo "$name : $value <br />";
        }
      }
    ?>
    Code (markup):
    What I want to do, is to just display the value of a specific key withing the array. I.e. how can I display the value for "cookie[two]"??

    :confused:
     
    domokun, Feb 13, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    print $_COOKIE['two'];
     
    crivion, Feb 13, 2009 IP
  3. domokun

    domokun Peon

    Messages:
    151
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Tried that, doesn't work :(
     
    domokun, Feb 13, 2009 IP
  4. domokun

    domokun Peon

    Messages:
    151
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ah! Figured it out

    echo $_COOKIE["csscookie"]["two"];

    Thanks!
     
    domokun, Feb 13, 2009 IP