Skip to Content
PHP Cookbook
book

PHP Cookbook

by David Sklar, Adam Trachtenberg
November 2002
Intermediate to advanced
640 pages
16h 33m
English
O'Reilly Media, Inc.
Content preview from PHP Cookbook

8.23. Setting Configuration Variables

Problem

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

Solution

Use ini_set( ) :

// add a directory to the include path
ini_set('include_path', ini_get('include_path') . ':/home/fezzik/php');

Discussion

Configuration variables are not permanently changed by ini_set( ). The new value lasts only for the duration of the request in which ini_set( ) is called. To make a persistent modification, alter the values stored in the php.ini file.

It isn’t meaningful to alter certain variables, such as asp_tags or register_globals because by the time you call ini_set( ) to modify the setting, it’s too late to change the behavior the setting affects. If a variable can’t be changed, ini_set( ) returns false.

However, it is useful to alter configuration variables in certain pages. For example, if you’re running a script from the command line, set html_errors to off.

To reset a variable back to its original setting, use ini_restore( ):

ini_restore('sendmail_from'); // go back to the default value

See Also

Recipe 8.23 on getting values of configuration variables; documentation on ini_set( ) at http://www.php.net/ini-set and ini_restore( ) at http://www.php.net/ini-restore.

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.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
PHP Cookbook, 2nd Edition

PHP Cookbook, 2nd Edition

Adam Trachtenberg, David Sklar
PHP Cookbook, 3rd Edition

PHP Cookbook, 3rd Edition

David Sklar, Adam Trachtenberg
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe

Publisher Resources

ISBN: 1565926811Supplemental ContentCatalog PageErrata