Sathishkumar
Sathishkumar

Reputation: 3414

PHP Curl Not working for HTTPS page

I try to submit the values thro post method using with PHP Curl. But it is not working on HTTPS pages. Any body review my below code and check what I did wrong.

$url = 'https://www.whoisxmlapi.com/user/create.php';
$fields = array(
                        'username' => urlencode("check123"),
                        'email' => urlencode("[email protected]"),
                        'password' => urlencode("password"),
                        'password_confirmation' => urlencode("password"),
                        'firstname' => urlencode("firstname"),
                        'lastname' => urlencode("lastname"),
                        'organization' => urlencode("organization"),
                        'captcha' => urlencode("captcha")
                );

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');


//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($ch,CURLOPT_TIMEOUT, 20);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

Upvotes: 1

Views: 860

Answers (2)

Farhad
Farhad

Reputation: 2003

share errors that you got, or test with this curl options

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

0: Don’t check the common name (CN) attribute

1: Check that the common name attribute at least exists

2: Check that the common name exists and that it matches the host name of the server

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94682

Please start by adding some useful error checking to your code

//execute post
$result = curl_exec($ch);

if( $result === false) {
    echo 'Curl error: ' . curl_error($ch);
}

Then you will probably be able to solve your own problem

Upvotes: 2

Related Questions