InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

Menu
  • Home
  • Sitemap

Python Programming Language Best Tutorials and Code Examples

Learn Python Right Now!
Home
PHP
Reading Configuration Variables in PHP
PHP

Reading Configuration Variables in PHP

InfinityCoder December 23, 2016

You want to get the value of a PHP configuration setting.

Use ini_get():

1
2
// find out the include path:
$include_path = ini_get('include_path');

To get all the 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:

1
2
3
// Put all config values in an associative array
$vars = ini_get_all();
print_r($vars['date.timezone']);

This prints:

1
2
3
4
5
6
Array
(
    [global_value] => UTC
    [local_value] => UTC
    [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 20-1 explains the values for access. Note that the name access is a little misleading in this respect because the value of the setting can always be checked, but not always adjusted.
Table 20-1. Access values

Value PHP constant Meaning
1

2

4

7

PHP_INI_USER

PHP_INI_PERDIR

PHP_INI_SYSTEM

PHP_INI_ALL

Any script, using ini_set()

Directory level, using .htaccess

System level, using php.ini or httpd.conf

Everywhere: scripts, directories, and the system

A value of 6 means the setting can be changed in both the directory and system level, as 2 + 4 = 6.

In practice, there are no variables modifiable only in PHP_INI_USER or PHP_INI_PERDIR, and all variables are modifiable in PHP_INI_SYSTEM, so everything has a value of 4, 6, or 7.
You can also get variables belonging to a specific extension by passing the extension name to ini_get_all():

1
2
// return just the session module specific variables
$session = ini_get_all('session');

By convention, the variables for an extension are prefixed with the extension name and a period. So all the session variables begin with session. and all the PDO variables begin with pdo, for example.
Because ini_get() returns the current value for a configuration directive, if you want to check the original value from the php.ini file, use get_cfg_var():

1
$original = get_cfg_var('sendmail_from'); // have we changed our address?

The value returned by get_cfg_var() is the same as what appears in the global_val ue element of the array returned by ini_get_all().

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Hiding Error Messages from Users in PHP
You don’t want PHP error messages to be visible to …

Hiding Error Messages from Users in PHP

Flushing Output to a File in PHP
You want to force all buffered data to be written …

Flushing Output to a File in PHP

About The Author

InfinityCoder
InfinityCoder

Leave a Reply

Cancel reply

Recent Tutorials InfinityQuest

  • Adding New Features to bash Using Loadable Built-ins in bash
    Adding New Features to bash Using Loadable …
    June 27, 2017 0
  • Getting to the Bottom of Things in bash
    Getting to the Bottom of Things in …
    June 27, 2017 0

Recent Comments

  • fer on Turning a Dictionary into XML in Python
  • mahesh on Turning a Dictionary into XML in Python

Categories

  • Bash
  • PHP
  • Python
  • Uncategorized

InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

About Us

Start learning your desired programming language with InfinityQuest.com.

On our website you can access any tutorial that you want with video and code examples.

We are very happy and honored that InfinityQuest.com has been listed as a recommended learning website for students.

Popular Tags

binary data python CIDR convert string into datetime python create xml from dict python dictionary into xml python how to create xml with dict in Python how to write binary data in Python IP Address read binary data python tutorial string as date object python string to datetime python

Archives

  • June 2017
  • April 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
Copyright © 2021 InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more
Programming Tutorials | Sitemap