我正在使用以下代码
echo 'file_get_contents : ', ini_get('allow_url_fopen') ? 'Enabled' : 'Disabled';
这可以启用或禁用它
但我想将其作为函数,函数名为_isgetcontents
然后我可以在我的网站代码中的任何位置调用它
if (_isgetcontents()){
echo "this is enabled"; // will do an action
}else{
echo "this is disabled"; // will do another action
}
if()
不可靠,因为ini_get()
返回配置选项的字符串,例如它可能返回字符串'Off'
,而条件语句会将其视为true
。这应该是正确的检查方式:if ( filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN ) )
- Pablo S G Pacheco