Usage of ini_set()

In this post, we will be discussing about What, Why and Usage of ini_set().

What is ini_set()?

It enables you to override some php function. For example, If upload_size is set to 2mb on global php.ini, then client/user can override global php.ini file setting for that perticular website using ini_set().
ini_set() function requires two string arguments. First one is the setting name and the second one is the value.

Why to use ini_set()?

First let me tell you, that using ini_set() is risky and should not be enabled on shared server. You should always search for an alternate if possible.

However, if necessary you can use it, as it gives huge help to developers and system admins.

Usage of ini_set()

For example: If on global php.ini file display_errors function is disabled and for your website/application/page you need display_errors to be enabled. In such case without asking system admin to enable display_errors function, you can on your end enable this function with the help of ini_set function by adding below line on top of your website/application/page.

ini_set('display_errors', '1');

You also need to know that all php functions are not changeable by ini_set(). Go through the list and check changeable column. In this column only functions with value PHP_INI_USER or PHP_INI_ALL can be overridden.

Values you update via ini_set() are applicable only to current website/application/page. After that global php.ini values will take into affect.

Hope you liked this post.


Please follow and like us:

Leave a Reply

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