php cookie doesn't update

前端 未结 5 498
遥遥无期
遥遥无期 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:26

    This is syntax for setting a cookie

    setcookie(name, value, expire, path, domain);
    

    When you create a cookie, using the function setcookie, you must specify three arguments. These arguments are setcookie(name, value, expiration):

    1. name: The name of your cookie. You will use this name to later retrieve your cookie, so don't forget it!
    2. value: The value that is stored in your cookie. Common values are username(string) and last visit(date).
    3. expiration: The date when the cookie will expire and be deleted. If you do not set this expiration date, then it will be treated as a session cookie and be removed when the browser is restarted.

    Note:- This will rewrite your cookie not update.

提交回复
热议问题