简体   繁体   中英

Sending headers in beforeFilter of Controller in CakePHP 2

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM