xnote
xnote

Reputation: 89

Curl https xml result returns blank (boolean false) in PHP

Please need your help! I send a post using cURL but the response is blank (boolean false). If I post the data on browser like just pressing the https://www.example.com/myaccount/transfer.php?username=usernamer&password=pass&deposit=5 the browser shows the following result:

1 0 success Your account has been deposited.

When I see the browser source code the results are:

<?xml version="1.0" encoding="utf-8"?>
<TransferResponse>
<version>1</version>
<result>0</result>
<resultstring>success</resultstring>
<description>Your account has been deposited</description>
</TransferResponse>

Let me attach the my cURL code:

<?php

$config = array
(
"url"        => "https://www.example.com/myaccount/",
"transfer"   => "transfer.php",
"browser"    => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);

$postFields = "username=username&password=pass&deposit=5";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url'] . $config['transfer']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/cert/GeoTrustGlobalCA.crt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config['browser']);
curl_setopt($ch, CURLOPT_REFERER, $config['url']);
curl_setopt($ch, CURLOPT_HEADER, true);

$content = curl_exec($ch);

var_dump($content);
var_dump(curl_getinfo($ch));
curl_error($ch);

curl_close($ch);

echo $content;

?>

Please, assist me to get the result in cURL. I have tried many ways. I have surfed internet for 2 days straight. At last I decided to ask here. Can someone figure out what the problem is? The followings are done:

Upvotes: 1

Views: 6620

Answers (2)

Hafiz Ismail
Hafiz Ismail

Reputation: 3225

Setting SSL verification to false defeats the purpose of SSL. A proper solution is to set the CA certs for CURL.

Solution 1 (Changes to PHP.ini):

  1. Download CA bundle (cacert.pem) from http://curl.haxx.se/docs/caextract.html
  2. Place it on your local system (for eg: C:\xampp\cacert.pem)
  3. Open your php.ini
  4. Set the curl.ca_info options to point to the location of the cacert.pem

    Example: curl.ca_info="C:\xampp\cacert.pem"
    
  5. Restart Apache

Solution 2 (Set options before each CURL call)

  1. Download CA bundle (cacert.pem) from http://curl.haxx.se/docs/caextract.html
  2. Place it on your local system (for eg: C:\xampp\cacert.pem)
  3. Write the following code:

    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE); 
    curl_setopt ($ch, CURLOPT_CAINFO, "pathto\cacert.pem");
    

Source: http://tumblr.wehavefaces.net/post/52114563111/environment-windows-xampp-curl-library

Upvotes: 1

Pekka
Pekka

Reputation: 449435

If this

SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

is your problem, the curl_setopt() setting

CURLOPT_SSL_VERIFYPEER

might be for you:

FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option.

So set

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

and probably also

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

Upvotes: 1

Related Questions