3

This is the warning.

Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /.../file.php on line 41

This is what I am using to detect cURL. If cURL isn't enabled a work around is triggered.

function curlEnabled() {
    if (ini_get('safe_mode') == 1)
        return 0;

    return in_array('curl', get_loaded_extensions());
}

I am finding it very difficult to test this function effectively do to a lack of hosting with safe mode enabled or cURL disabled.

Could someone tell me.

  1. Does the function actually detect PHP safe_mode?
  2. It detects whether cURL is loaded right?

Finally, how would this function be improved to catch the 'cannot be activated' error and return 0?

Christian
  • 27,509
  • 17
  • 111
  • 155
John Paul
  • 59
  • 1
  • 2
  • 7

1 Answers1

6

That seems to work correctly with safe_mode.

To check CURL, you can either look for it in the loaded extensions (as you did), or simply:

function_exists('curl_init');

With regards to the error message, I'm not sure what you're asking. Do you want to suppress the error message?

You can do something like:

$old=error_reporting(0); // turn off error reporting
// do whatever that causes errors
error_reporting($old);   // turn it back on
Christian
  • 27,509
  • 17
  • 111
  • 155
  • To clarify, the warning means that the curlEnabled function returned 1 and the cURL code was run - even though apparently the host has trouble running it. What I want to do is be able to detect whatever is causing this warning and whether cURL actually works without generating an error or warning. I don't mind using error suppression. It is the test that I am having trouble with. – John Paul May 03 '11 at 08:06
  • @John Paul - Since it is a warning, the code should continue running, hence you should be able to run your test successfully. – Christian May 03 '11 at 10:11