[SOLVED] Help on Cookie!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Phoenixheart
Forum Contributor
Posts: 123
Joined: Tue Nov 16, 2004 7:46 am
Contact:

[SOLVED] Help on Cookie!

Post by Phoenixheart »

I can't find any documentation to help on this problem, so I post it here.

Code: Select all

<?php
// set the cookies
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
setcookie("cookie[one]", "cookieone");

// after the page reloads, print them out
if (isset($_COOKIE['cookie'])) {
   foreach ($_COOKIE['cookie'] as $name => $value) {
       echo "$name : $value <br />\n";
   }
}
?>
Everyone knows these code are in the php manual. But (at least as I know) they don't mention how to update the cookie. That means, how do I change the value in "cookie[two]" to "another_value" other than "cookietwo"? Or, how to delete the "cookie[one]" from the "cookie" array? Please help me out.


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Last edited by Phoenixheart on Tue Mar 22, 2005 7:49 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just set the cookie again with it's new value :wink:

To delete the cookie, set it's date in the past.
Post Reply