phpの設定オプション指定方法(php.ini、 httpd.conf/.htaccess、php_ini等)

phpの設定オプション指定方法は、4種類

  • php.ini
  • httpd.conf
  • .htaccess
  • プログラム中に関数を呼び出す(ini_setなど)

それぞれの設定の仕方によって、設定オプションの有効にできる値と、できない値があります。
どれが有効化は、PHPのヘルプに一覧が載っています。
PHP: php.ini ディレクティブ - Manual

※Windowsの場合はレジストリでも設定できるそうです。まず使わないかと思われますが。

それぞれの書き方

php.ini

CODE:
  1. magic_quotes_gpc = off
  2. output_buffering = off
  3. mbstring.language = Japanese
  4. mbstring.encoding_translation = off
  5. mbstring.http_input = pass
  6. mbstring.http_output = pass
  7. mbstring.internal_encoding = EUC-JP
  8. mbstring.substitute_character = none
  9. mbstring.detect_order = SJIS,EUC-JP,JIS,UTF-8,ASCII

httpd.conf と .htaccess(設定可能なオプションが違うけど、書式は同じ)

CODE:
  1. php_flag magic_quotes_gpc off
  2. php_flag output_buffering off
  3. php_value mbstring.language Japanese
  4. php_value mbstring.internal_encoding UTF-8
  5. php_flag mbstring.encoding_translation off
  6. php_value mbstring.http_input pass
  7. php_value mbstring.http_output pass
  8. php_value mbstring.substitute_character none
  9. php_value mbstring.detect_order SJIS,EUC-JP,JIS,UTF-8,ASCII

以下のディレクティブでくくると、そのバージョンのモジュールのみ適用

CODE:
  1. <IfModule mod_php5.c>
  2. php_flag magic_quotes_gpc off
  3. </IfModule>
  4. <IfModule mod_php4.c>
  5. php_flag magic_quotes_gpc on
  6. </IfModule>

プログラム中

PHP:
  1. //ini_set関数を使う
  2. ini_set('magic_quotes_gpc', 'off');
  3. ini_set('mbstring.internal_encoding', 'UTF-8');
  4. ini_set('mbstring.http_input', 'pass');
  5. ini_set('mbstring.http_output', 'pass');
  6. ini_set('mbstring.substitute_character ', 'none');
  7. ini_set('mbstring.detect_order 'SJIS,EUC-JP,JIS,UTF-8,ASCII');

PHP:
  1. //それ用の関数を使う
  2. mb_language('Japanese');
  3. mb_http_input('UTF-8');
  4. mb_http_output('UTF-8');

コメント・トラックバック

コメントを送る
※は入力必須です。コメントは管理者の承認後に表示されます。