php setcookie not working with ajax call

前端 未结 2 1250
萌比男神i
萌比男神i 2020-12-06 17:22

I have a page, test.php, with the following code:


    
        
相关标签:
2条回答
  • 2020-12-06 17:33

    If you don't add a $path value to setcookie(), it defaults to "the current directory". This means that if you set the cookie from /web/DEV/Classes/SetCookie.php, the cookie gets set to /web/DEV/Classes/, and anything above that path won't see that cookie.

    To fix this, add a specific $path to setcookie. If your app runs on the domain root (example.com), use '/'. If it's in a subfolder (example.com/myapp/), use '/myapp/'

    setcookie("TestCookie", $var, time()+60*60*24*30, '/');
    
    0 讨论(0)
  • 2020-12-06 17:49

    I think you should look into the path parameter of the setcookie. Set it to "/" , so that it is accessible from across all directories/pages of the site.

    0 讨论(0)
提交回复
热议问题