29

I'm using the following code

echo 'file_get_contents : ', ini_get('allow_url_fopen') ? 'Enabled' : 'Disabled';

this can get it enabled or disabled

but I would like to make as function say function name is _isgetcontents

then I can call it as following any where in my website code

if (_isgetcontents()){
  echo "this is enabled"; // will do an action
}else{
  echo "this is disabled"; // will do another action
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Reham Fahmy
  • 4,937
  • 15
  • 50
  • 71

2 Answers2

73

Use ini_get() (docs) to get the value of certain configuration parameters:

if( \filter_var( \ini_get('allow_url_fopen'), \FILTER_VALIDATE_BOOLEAN ) ) {
   // lucky me...
} 
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • That `if()` is not reliable, as `ini_get()` returns a string of the configuration option, i.e., it could return the string `'Off'` and the conditional would consider it `true`. This should be the right check: `if ( filter_var( ini_get( 'allow_url_fopen' ), FILTER_VALIDATE_BOOLEAN ) )` – Pablo S G Pacheco Nov 17 '22 at 16:38
  • 1
    That's valid point. I edited my answer to include your filter for those who do not read but do copy&paste coding. Thanks. – Marcin Orlowski Nov 17 '22 at 18:06
  • Sure, thanks for changing it. Sometimes I do that myself :) – Pablo S G Pacheco Nov 17 '22 at 21:13
2

you can also use this method

phpinfo()

to check various configurations.

Faiyaz Alam
  • 1,191
  • 9
  • 27