简体   繁体   中英

Setting a cookie in an ajax call's echo page

I attempted to set a cookie while in an ajax call page, where you echo the data received by the ajax call and got an error message. I'm not sure what it could mean or how to fix it. Setting cookies works fine when they're not being use in ajax calls page, where you echo the info received.

setcookie("TestCookie", $value, 0, '/', ".websiteName.com");

Got the following error message. No idea what it could mean.

Warning: Cannot modify header information - headers already sent by 

The full error, which was not shown implies that the headers have already been set. If you would like to use setcookie() you will need to place the call before any of the HTML has been sent out to the user.

The header information is sent out first and can not be modified post process.

In most cases moving setcookie() to the top after

<?php

Will solve the error, as long as it placed before any output(html) has been sent out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM