开发者

PHP: using setcookie at the beginning of AJAX request does not save cookie post-request?

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[$filtersCooki开发者_开发知识库e])) {

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.


I dont think the browser will intercept the cookie when ajax call. You can do a work around like setting the cookie from javascript.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜