How do I check if ini_set() is enabled either in the global PHP.INI or in my PHP script?

百般思念 提交于 2019-12-05 11:57:35

I did some research on this, and it turns out that sometimes ini_set will not return FALSE, but an empty string. This is mentioned in the URL pointed out by gabriel1836. The best way to check if it works is to first check the disable_functions flag in php.ini to see if it is disabled, and then (if it is not disabled), change a value with it, and echo phpinfo() immediately after. If the value is changed under the local column, then you know ini_set works.

You might want to take a look at the CHANGEABLE directives in php.ini: http://us3.php.net/manual/en/ini.php#ini.list

In regard to verify whether an ini_set function worked, you can check the return value to make certain that it worked: http://us3.php.net/manual/en/function.ini-set.php

The code would look something like this:

<?php
     if(ini_set('error_reporting', 'ALL') === false)
     {
         // Perform failure handling logic
     }
?>

You could check the disable_functions setting in your php.ini file. That's pretty much the only thing I can think of. I doubt it would be set, though, unless you're running on shared hosting or something like that.

You might also want to check if the relevant setting is specified using php_admin_flag or php_admin_value in your Apache config, as those will effectively "lock" the setting and keep ini_set() from changing it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!