我不明白这一点,因为这对我来说似乎很奇怪 - cookie:没有我在第一次执行时设置的数据。
我的代码,
$booking_time = '12:00';
$timeslots = array(
array(
"12:00",
"12:30",
"13:00",
"13:30",
"14:00",
"14:30"
),
array(
"15:00",
"15:30",
"16:00",
"16:30",
"17:00",
"17:30"
)
);
//print_r($timeslots);
$selected_timeslot_start = null;
$selected_timeslot_end = null;
$selected_date = '2013-10-30';
foreach($timeslots as $index => $timeslot)
{
if(in_array($booking_time, $timeslot))
{
$selected_timeslot_start = $timeslot[0].':00'; // first item.
$selected_timeslot_end = end($timeslot).':00'; // last item
//echo 'from = '.$timeslot[0];
//echo ' to = '.end($timeslot);
//print_r($timeslot);
setcookie("selected_timeslot_start", $selected_timeslot_start, time()+1800 , '/');
setcookie("selected_timeslot_end", $selected_timeslot_end, time()+1800 , '/');
setcookie("selected_date", $selected_date, time()+1800 , '/');
}
}
print_r($_COOKIE);
我明白了,
Array
(
[__atuvc] => 46|39
[PHPSESSID] => olvlb3sv6bscvbpkva4d9ev6p3
)
然后我在浏览器上点击刷新,我得到了所有的数据,
Array
(
[__atuvc] => 46|39
[PHPSESSID] => olvlb3sv6bscvbpkva4d9ev6p3
[selected_timeslot_start] => 12:00:00
[selected_timeslot_end] => 14:30:00
[selected_date] => 2013-10-30
)
为什么 - 有人能告诉我我在 cookie 上做错了什么吗?