Why is php not removing cookie set by javascript?

后端 未结 1 411
遥遥无期
遥遥无期 2020-12-20 06:39

There is post comment box on my site.

Posting comment is handled by javascript, js posts data to php script and php does the db related stuff and shows confirmation

相关标签:
1条回答
  • 2020-12-20 07:21

    You need to make sure the all the parameters (except name and time depending on the cookie.) are same while Setting Cookie in Javascript and while Removing Cookie in PHP

    Parameters i.e. name,path (value and expire time can be different.)

    for eg.

    While setting cookie in javascript if you use it like this

    document.cookie = id + "=" + input_text + " ; path=/";
    

    you set the path to "/"

    then while removing cookie in php you should specifically set like this.

    //remove cookie.
    setcookie($id, "", time()-36000 , "/");
    
    0 讨论(0)
提交回复
热议问题