8.22. Reading Configuration Variables
Problem
You want to get the value of a PHP configuration setting.
Solution
Use ini_get( )
:
// find out the include path:
$include_path = ini_get('include_path');Discussion
To get all configuration variable values in one step, call
ini_get_all( )
. It returns the variables in an
associative array, and each array element
is itself an associative array. The second array has three elements:
a global value for the setting, a local value, and an access code:
// put all configuration variables in an associative array $vars = ini_get_all( ); print_r($vars['include_path']); Array ( [global_value] => .:/usr/local/lib/php/ [local_value] => .:/usr/local/lib/php/ [access] => 7 )
The global_value is the value set from the
php.ini file; the local_value
is adjusted to account for any changes made in the web
server’s configuration file, any relevant
.htaccess files, and the current script. The
value of access is a numeric constant representing
the places where this value can be altered. Table 8-3 explains the values for
access. Note that the name
access is a little misleading in this respect, as
the setting’s value can always be checked, but not
adjusted.
Table 8-3. Access values
|
Value |
PHP constant |
Meaning |
|---|---|---|
|
|
|
Any script, using |
|
|
|
Directory level, using .htaccess |
|
|
|
System level, using php.ini or httpd.conf |
|
|
|
Everywhere: scripts, directories, and the system |
A value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access