dse323222 2011-07-15 05:46
浏览 311
已采纳

PHP:在AJAX请求开始时使用setcookie不保存cookie后请求?

whenever the ajax page is called, i run:

setcookie($filtersCookie, $cookieVal, time() + 86400); // 1 day

and when the page is refreshed, i use the following code to see if there were any past filters saved:

if(isset($_COOKIE[$filtersCookie])) {

but the cookie never exists after a page refresh. any ideas as to why this may happen?

setcookie is used before any browser output from the ajax call.

  • 写回答

2条回答 默认 最新

  • douzhuan1169 2011-07-15 06:09
    关注

    If your Ajax scripts resides in another directory than the calling page, then you should also use the path parameter

    setcookie($filtersCookie, $cookieVal, time() + 86400, "/"); // 1 day
    

    By default the cookie will be available from the directory the cookie is set on, using "/" will make it available to all paths.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?