CakePHP and “Cannot modify header information” warning. (Not a whitespace problem)

Yesterday I spend too much time trying to solve following problem. While working with CakePHP, writing some login function I need to use redirection.

But the redirection didn’t work:

Cannot modify header information - headers already sent by (output started at
C:\xampp\htdocs\cool\app\controllers\users_controller.php:1)

Of course I checked all my code and then looked for some solution on Internet. The one, that repeats from page to page is that there is a white space or another character after “?>”.

But not in my case.

In my app everything start to work after I changed the encoding of the files to ANSI. (Before was UTF8). It works also with UTF8 without BOM. It seems to be more or less obvious, but without diving into the encoding issues it is difficult to explain. (Maybe next time)

And one more thing: the problem is related with PHP in general, not just CakePHP, so Cake stays blessed (so far…).