note 50156 added to function.setcookie
| From: | DannyLin at osu1 dot php dot net | Date: | Sun, 20 Feb 2005 04:37:07 +0000 |
| Subject: | note 50156 added to function.setcookie | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85261@lists.php.net to get a copy of this message | ||
I have XP Home and IE6. I tried the example 3:
<?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";
}
}
?>
And it worked. However, when I added expiration info, it stopped working. Then, I noticed that it
might be related to the time() on my server (hosted in Texas). With the debugging code below, I
found out I have to add two hours. (You will need to "fresh" the browser to get the
cookies set.)
<?
for ($i = 0; $i < 10; $i++) {
$time[$i] = time();
setcookie("time_report[$i]",$time[$i], $time[$i]+3600*$i);
}
print_r($_COOKIE);
?>
----
Manual Page -- http://www.php.net/manual/en/function.setcookie.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50156
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50156&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50156&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50156&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50156&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50156&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50156&report=yes
Search -- http://master.php.net/manage/user-notes.php