php cookie doesn't update

前端 未结 5 497
遥遥无期
遥遥无期 2021-01-21 17:08

I need to update a cookie. I do that in a php file called via ajax. This is is the code:

setcookie(\'items[\'.$_POST[\'id\'].\']\');

The cookie

5条回答
  •  迷失自我
    2021-01-21 17:37

    You cannot set and access a cookie in the same instance/page. You have to do a redirect or refresh after setting it.

    In addition, you should do something like this instead :

    setcookie("id","items['.{$_POST['id']}.']");
    

提交回复
热议问题