1

I have myController which is extended from AppController.
Inside myController::beforeFilter I put this line:

header('HTTP/1.0 401 Unauthorized', true, 401);

But I can't see this data inside response headers.
I don't have any whitespace inside this class neither in AppController.
Where should I look or how can I debug this issue?
Thank you

1 Answer 1

3

Instead of using PHP's header function, you'll want to use Cake's:

In AppController::beforeFilter:

$this->header('HTTP/1.0 401 Unauthorized');

Using Cake's built in header function queues the headers and sends them all at once when it's ready. I think your problem is likely because you're outputting a header at the wrong time.

Sign up to request clarification or add additional context in comments.

4 Comments

Also I should mention that sending headers from controller file is deprecated, it should be sent from view file.
I can't seem to find where it says this method is deprecated - can you provide a link?
Isn't it only the wrapper function that is deprecated? CakeResponse::header is still what you should use (also I don't see anything about putting this in the view).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.