views:

238

answers:

1

Hi,

I have a ajax login script, using prototype, where I ajax the credentials over to a php page that checks if the info is correct. If it is, I try to set a cookie and then return 0 or 1 depending if it is correct. The ajax call returns 0 if it is correct and then makes a js call on the original page to redirect into the site. I keep getting a cannot modify header information error. What am I doing wrong?

Thanks

+2  A: 

Check that your PHP isn't outputting any content before the line which sets the cookie. This includes whitespace - so make sure your code doesn't look like this:

<!-- some comment, new line, or something else before the php opening tag -->
<?php // This should be on line 1, with no space before it.
digitala
+ make sure, that no includes have any whitespace outside of <?php ?> blocks, including after closing the last ?>. That's why many frameworks recommend omitting the closing ?> in files, as the PHP interpreter stops at the end of files. See also http://stackoverflow.com/questions/236493/what-are-the-arguments-in-favor-of-php-closing-tags-for-php-only-files
Residuum
also check that you do not print/echo anything before finishing setting the cookie. if you use output buffering then make sure you don't flush before finishing with the cookie.
daniels