14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHPでredirectが効かない時の対処

Last updated at Posted at 2014-04-11

#現象

画面が真っ白。
または以下のエラーが出る。

Warning: Cannot modify header information - headers already sent ..

#原因

リダイレクト前に何か出力してるから。
例えば、こんな感じ。

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

この場合、1行目のデバッグを出力してる部分でHTTPヘッダが送信され(headers already sent)るので、2行目のリダイレクトで新しいヘッダを送信しようとすると、Cannot modify header informationになってしまう、ようだ。詳しい理由は知らない。

#対処

php.iniの

php.ini
output_buffering = Off

php.ini
output_buffering = On

に書き換えてApacheを再起動するだけ。

14
15
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?