PHP values in .htaccess files (Apache)

A lot of time you host your website where you do not have direct access to the php.ini file (pretty much any shared hosting). In this case, if you need to make a change to your php configuration settings, you simply add an entry to your .htaccess file in the folder that your website is located in. Of course, the hosting provider will need to have set AllowOveride on your account, but most will already have this set up for you. The are two types of lines you can put in a .htaccess file:

php_value name value
php_flag name on|off

They can both be used for any configuration option specified as a PHP_INI_ALL or PHP_INI_PERDIR. However, most of the time you will use php_value, which allows you to specify a number as a value. The php_flag option can only be used for certain configuration options that only have two possible values (on or off). To find out what the default setting is and to see if you can change it in an .htaccess file, look at the following list.

So, for example, you can use either of the following two options to turn on register_globals:

php_flag register_globals on

php_value register_globals 1

They both will do the same thing and neither one is necessarily better then the other. Here’s a list of some other common php changes to an .htaccess file:

php_value output_buffering 1

php_value session.auto_start 1

php_flag magic_quotes_gpc on

php_value register_argc_argv 0

php_value display_errors 1

php_value error_reporting 63

Hope this helps someone!

Leave a comment

Your email address will not be published. Required fields are marked *