views:

39

answers:

2

i used mvc concept for my project...

i can set cookies index page...

but i can not set cookies in view page,,,

i received the following warning...

Warning: Cannot modify header information - headers already sent by...

thanks advance

A: 

Cookies are set by sending a HTTP header to the browser.

Headers must all be sent before any content is sent to the client. Your code must be sending some content before it attempts to set the cookie.

A quick fix it to use output buffering (http://php.net/manual/en/ref.outcontrol.php) to cache the output and send it all when the script is finished. A better idea is to restructure your code though so that you aren't mixing up logic such as setting cookies with the display layer.

benlumley
A: 

Cookies and other headers must be set before anything is sent to the browser, this includes whitespace. Ensure there are no line breaks or any other output before you set the cookie.

Furthermore, your cookies should really be set in the controller not the view which may help fix your issue, depending on how your final output is constructed. This question would also benefit from code examples to help us be more specific.

akamike
... and by 'line breaks', that can include "a couple of new lines after the closing ?> tag in a previously included file".
Narcissus