A PHP Trick to Override the php.ini Configuration

I’m glad that my hosting provider lets me edit the php.ini configuration file directly inside of the Control Panel. But many hosting providers don’t let their users to edit the php.ini file in case of server overload. Here are two methods to change/override the configuration of php.ini without open up the file or it is forbidden to edit by the hosting provider.

.htaccess method

To use this method, the hosting provider must use Apache and enabled “AllowOverride Options” or “AllowOverride All” privillage in the Apache httpd.conf file to allow users to override the default PHP configuration as well as Apache’s by using .htaccess. Two types of values are acceptable inside .htaccess file: php _flag is used for switch value and php_value is used for other types of value. For example:

php_flag register_globals off  // Disables global – set it to “on” or “off”
php_value upload_max_filesize 100M // Increase or decrease max file upload size to 100 MB
php_value max_execution_time 30 // Change the time allowed to run PHP scripts to 30 seconds

Also noted that this solution will not work on all Apache platforms.

PHP in_set method

PHP in_set function is most portable and effective method to change the PHP configuration on the fly during the application runtime. It accepts all types of values, including booleans and strings.

Bansal Sumit

To seek challenging roles and to achieve excellence in the field of Open Source Web Technology with a profound spirit of commitment and dedication.

You may also like...

Leave a Reply

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