开发者

Echoing a variable in php gives one number and setting the variable to a cookie and evaluating the cookie gives another?

I have a variable in a post array called childnumber, which was a javascript variable sent to the server via an ajax post. In the php script it is here:

$newValue = $_POST["childnumber"]+1;

I have added 1 to it. Echoing $newvalue in the php script and sending it back to the client via the ajax response gives the correct number on the clientside html. But if I set the cookie

setcookie($cookieName,$newValue);

in the php instead of echoing it back to the client and check the cookies clientside the cookiename is correct but the new value comes out as j开发者_JAVA百科ust '1' everytime. So how do I get the cookie value to be the value which is echoed back to the client?

Thanks


As I understand your process, you send an asynchronous request, process it by setting a cookie and... what do you send back?

I might be wrong (and be glad for any clarification from others) but does not the cookies are set along the http headers and therefore are accessible after you "reload" or redirect to new/same page?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜