isset($ _ COOKIE)无效

时间:2017-06-12 21:17:54

标签: php cookies

服务器是我的电脑(http://127.0.0.1/),我检查了Cookie是否已创建。

这是我的代码。此代码按表单获得“selected_item_no”,并创建或覆盖cookie。查看评论为GetWorldTimerManager().SetTimer(HarvestTimerHandle, this, &ACubeFarmBlock::Harvest, HarvestTime,false); 的行:

//Issue is here

<?php session_start(); $selected_item_no=$_POST["selected_item_no"]; $search_item=$_POST["search_item"]; $search_text=$_POST["search_text"]; $isadded = 0; if((trim($selected_item_no)!="")) { if (isset($_COOKIE["maxcount"])) { $maxcount = $_COOKIE["maxcount"]; for($ii=1;$ii<=$maxcount;$ii++){ ////////// ISSUE IS HERE if(isset($_COOKIE["cart_item_no[$ii]"])){ // this line doesn't work ///////// $temp_item_no = $_COOKIE["cart_item_no[$ii]"]; if(trim($temp_item_no)===trim($selected_item_no)){ $temp_item_count = $_COOKIE["cart_item_count[$ii]"] + 1; setcookie("cart_item_count[$ii]", $temp_item_count, time()+3600, "/"); $temp_arr_i = $ii; $isadded = 1; break; } } } if($isadded == 0){ $maxcount = $ii; setcookie("maxcount", $maxcount, time()+3600, "/"); setcookie("cart_item_no[$maxcount]", $selected_item_no, time()+3600, "/"); setcookie("cart_item_count[$maxcount]", 1, time()+3600, "/"); $temp_arr_i = $ii; } } else { $maxcount = 1; setcookie("maxcount", $maxcount, time()+3600, "/"); setcookie("cart_item_no[$maxcount]", $selected_item_no, time()+3600, "/"); setcookie("cart_item_count[$maxcount]", 1, time()+3600, "/"); $temp_arr_i = $maxcount; } } $temp_count_tt = $_COOKIE["cart_item_count[$temp_arr_i]"]; ?> <html> <head> <?php include("./style.php"); ?> </head> <body> <?php if((trim($selected_item_no)!="")) { echo("$selected_item_no is added at $temp_arr_i . count: $temp_count_tt. isadded: $isadded.<br>"); var_dump($_COOKIE); } ?> 是这样的。换句话说,var_dump($_COOKIE)被定义为$_COOKIE["cart_item_no"]

中的数组
$_COOKIE

它不断增长。

我不知道如何解决这个问题...

1 个答案:

答案 0 :(得分:1)

你正在做错误的数组下载 正确的语法是$_COOKIE["cart_item_no"][$ii],而不是$_COOKIE["cart_item_no[$ii]"]