0

I've recently upgraded my test server from wamp (very old version) to a new version of xampp. Since the upgrade my CURL which I use to pull CSV data is failing.

I'm receiving the following error:

Warning: curl_setopt(): Curl option contains invalid characters (\0)

This error is appearing on

$ch = curl_init();

The full initialisation can be seen below:

// CURL Initialisation
$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $snowAuth);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Set the URL
curl_setopt($ch, CURLOPT_URL, $URL);

This has not changed at all between the webserver upgrades. I have checked php.ini and verified that php_curl is enabled and ensured that the extension_dir is correct as well (C:/xampp/php/ext).

Any ideas? I'm trying to rollback to an older version of XAMPP now.

Edit: The values of the variables are as follows (dummy data for security), also they are not retrieved from user input or extenal files:

$proxy = "10.0.0.128:8080"
$proxyAuth = "username:password"
$snowAuth = "diffusername:diffpassword"
Jovin J
  • 462
  • 5
  • 15
  • From @keupsonite: What is the content of the variables `$proxy`, `$proxyAuth`, `$snowAuth`? The data come from a user or another file? I think you have a BOM character on your file. You need to remove it. – Mr. Llama Jun 14 '16 at 23:51

1 Answers1

1

What is the content of the variables $proxy, $proxyAuth, $snowAuth ? The data come from a user or another file?

I think you have a BOM character on your file. You need to remove it.

Remove BOM character on Notepad++

Edit:

If the content of your variables come from an user or a file, please try this:

$removeBom = function($var) { return preg_replace('/\\0/', "", $var); };

// CURL Initialisation                                                          
$ch = curl_init();
curl_setopt($ch, CURLOPT_PROXY, $removeBom($proxy));
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $removeBom($proxyAuth));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $removeBom($snowAuth));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Set the URL                                                                  
curl_setopt($ch, CURLOPT_URL, $URL);
Community
  • 1
  • 1
keupsonite
  • 399
  • 3
  • 15
  • This is really a comment, not an answer. With a bit more rep, [you will be able to post comments](//stackoverflow.com/privileges/comment). For the moment I've added the comment for you, and I'm flagging this post for deletion. – Mr. Llama Jun 14 '16 at 23:50
  • I've tried converting to UTF-8 which did not resolve. The contents of the variables are in the main post as an edit for formatting reasons. Any further clues? I'm still in the process of uninstalling and rolling back to an older version. – Jovin J Jun 14 '16 at 23:54
  • @Jovin_ Added another solution, let me know if it helps. – keupsonite Jun 15 '16 at 00:06
  • 1
    @keupsonite The sanitisation function worked! Thanks for your help! – Jovin J Jun 15 '16 at 00:39
  • I'm glad to hear that! :) It was a pleasure. – keupsonite Jun 15 '16 at 00:49