1

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);
1
  • Have you any errors that you woudl ilke to share with us?? Commented Aug 8, 2015 at 15:26

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.