you need to set a cookie before sending any output to browser, example:
setcookie(...);
echo ''; // this works
echo '';
setcookie(...); // this not works
take a look at the source where you get that error message, search for html tags or anything (blank spaces...)