Home / PHP’s ini_get_all function

PHP’s ini_get_all function

PHP has a large number of configuration options which can be set in the php.ini file, Apache virtualhost settings, .htaccess and with the ini_set function. This post looks at the ini_get_all function which returns an array containing all the possible configuration options, what their global and local script value are and where they can be modified.

Sample code:

$options = ini_get_all();
print_r($options);

Example output:

Array
(
    [allow_call_time_pass_reference] => Array
        (
            [global_value] => 1
            [local_value] => 1
            [access] => 6
        )

    [allow_url_fopen] => Array
        (
            [global_value] => 1
            [local_value] => 1
            [access] => 4
        )

    ... more configuration options ...

    [zlib.output_handler] => Array
        (
            [global_value] => 
            [local_value] => 
            [access] => 7
        )

)

Accessing the values

The associative array that is returned contains a key name which is the configuration option name with a sub-array containing the keys ‘global_value’, ‘local_value’ and ‘access’. If you wanted to find out the local value for ‘allow_url_fopen’ for example, you could do something like this:

if($options['allow_url_fopen']['local_value'] == 1) {
    // do something
}
else {
    // do something else
}

Of course, you could also do the above using ini_get like this if all you needed was the local value:

if(ini_get('allow_url_fopen') == 1) {
    // do something
}
else {
    // do something else
}

Global value vs local value

The global_value contains the value that is set in the php.ini file. The local_value contains the modified value (if modified) in the <virtualhost>, .htaccess file or ini_set().

Access

Access uses the following PHP constants:

PHP_INI_USER 1 Entry can be set in user scripts
PHP_INI_PERDIR 2 Entry can be set in php.ini, .htaccess or httpd.conf
PHP_INI_SYSTEM 4 Entry can be set in php.ini or httpd.conf
PHP_INI_ALL 7 Entry can be set anywhere

The value can also be 6 i.e. PHP_INI_PERDIR + PHP_INI_SYSTEM.