CakePhp does not redirect to the Online server

Posted on

Question :

Good morning!

I’m using the cakephp framework, but I have a problem with no solution so far …
I have a login controller, I commented the entire login code and left only the trex


$ this-> redirect (array (‘controller’ => ‘nomedocontorller’, ‘action’ = > ‘home’));

In localhost this command works normally, I can direct the url, however, when I put it on the online server I simply get a blank page and no error message.

I have already checked spaces in the Index, routes, Controller, and View files, but there are no spaces before the php opening tag
I’ve already tried opening php just with



I have already uploaded a new cakePHP framework to the server to test if the problem was hidden in any of the files, but msm with the default cakephp files continued not directing.
I have already released debug mode to start the errors, but more so no error is reported, neither visually nor in the error log.


Answer :

After three days of fighting and some sleepless nights, I confess that I was already discouraged.

Today I woke up inspired to solve this problem and started to search the project for php tags that had empty spaces before or after the opening / closing.

To my happiness, I found around 5 files that had this problem, after correcting these files it seems that the targeting and session started working again.

Search for php tags that were opened / closed before or after the tags

(quebra de linha ou espaço)


(quebra de linha ou espaço)

After removing these occurrences, it appears that everything has returned to normal.
I had one more targeting problem, but I think it’s a bit different.

Thanks for everyone’s help!


This problem is common when headers are sent. Instead of redirect, try to use the following and see which error is returned:

<?php header( 'Location:' ) ; ?>

When using redirect, it is good practice to add it to return:

return $this->redirect(array('action' => 'index'));

In your action, add the debug below and note the return:

if (headers_sent($file, $line)) {
    exit("headers were already sent in file: {$file}, line number: {$line}");


Leave a Reply

Your email address will not be published. Required fields are marked *