2012/05/24

HTTPレスポンス ヘッダー Content-type


CIは デフォルトだと、Content-typeのcharsetが設定されていない
LiveHTTPHeaders で確認↓
HTTP/1.1 200 OK
Date: Thu, 05 May 2011 07:19:18 GMT
Server: Apache
X-Powered-By: PHP/5.3.5
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 977
Content-Type: text/html
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
これは セキュリティ上よろしくないので設定する
方法的には hookのpost_controllerでフックとかあるけど、
取り敢えず今回は コントローラの頭でやりゃーいいんじゃねーかと思ったので
コントローラー拡張クラス(いわゆるMY_Controller)のコンストラクタに↓下記をぺろっと追加
$this->output->set_header('Content-Type: text/html; charset=UTF-8');
で、確認↓
HTTP/1.1 200 OK
Date: Thu, 05 May 2011 07:28:49 GMT
Server: Apache
X-Powered-By: PHP/5.3.5
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 977
Content-Type: text/html; charset=UTF-8
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
今後、なにやら細かい設定がしたくなったら 設定は別クラス作って フックでもいいかと思う
参考)




0 件のコメント: