php setcookie not working with ajax call

前端 未结 2 1261
萌比男神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, '/');
    

提交回复
热议问题