If you’ve changed a configuration option and then later on want to put that option back to what it was, here’s your function.

You don’t need to save or ever know the original value. This function will take care of that for you.

Now, here’s the catch. This will not only undo a change made by ini_set() but also a change made in an .htaccess file. That is, you’ll get the system setting - as it is in php.ini or httpd.config.

With that in mind, you could use this function to “overrule” the .htaccess if you deem it necessary. For example, enforce the ini file setting for register_globals:

ini_restore('register_globals');

In this example, we change the error log location temporarily then change it back to what it was before.

$oldVal = ini_get('error_log');
ini_set('error_log', '/path/to/special/log/file');
 
/* your code here */
 
ini_set('error_log', $oldVal);