5

I found this code in the internet and I modified it for my use, I'm not sure what I'm doing wrong here, I'm getting this error Curl error: SSL connection timeout The login part is successful, but the search isn't working with me. can somebody help me with it please?

<?php
//create array of data to be posted
$post_data['username'] = 'user';
$post_data['password'] = 'log';
$post_data['cmd'] = 'log';

//create array of data to be posted
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
  curl_init('https://sie.com');
//set options
///curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 3990);

curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

curl_setopt($curl_connection, CURLOPT_HTTPHEADER, array(
    'Connection: Keep-Alive',
    'Keep-Alive: 300'
));

curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request

//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' .
  //              curl_error($curl_connection);
//close the connection
//curl_close($curl_connection);


echo $result."\n";


$post_data1['cmd'] = 'Viewr';
$post_data1['search'] = 'test';



foreach ( $post_data1 as $key => $value1) {
    $post_items1[] = $key . '=' . $value1;
}
$post_string1 = implode ('&', $post_items1);
echo $post_string1."\n";
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result1 = curl_exec($curl_connection);
//show information regarding the request
//$result1 =1;
//close the connection
//curl_close($curl_connection);
if ($result1)
echo "ok \n\n";
else
echo "nok\n";
if(curl_errno($curl_connection))
{
    echo 'Curl error: ' . curl_error($curl_connection)."\n";
}
echo($post_string1);
echo $result1."\n";


curl_close($curl_connection);


?>
3
  • Hi Craig, Not sure how to do that? Commented Jun 29, 2012 at 18:44
  • Next to the correct answer, below the rating Commented Jun 29, 2012 at 18:46
  • On your other questions, there is a checkmark next to all answers. Check the one which solved or assisted you in solving the issue. It matters. Commented Jun 29, 2012 at 18:46

3 Answers 3

4

Try adding this (But don't leave this option set in production!):

curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);

If it works afterwards, it is because CURL is failing to negotiate the SSL Certificate.

Follow this tutorial for steps on how to obtain the CA cert: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

Something else to look into is, before your curl_exec(), curl_copy_handle(); and then set additional parameters.

Additionally, or alternatively, you could re-initiate cURL with curl_init($url);.

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

5 Comments

it is set to false actually, I just checked it.
do you have Wireshark or TCPDUmp? Do you get a response back on 443? Or does it get hung on the TCP SYN?
So the login is working, which is the first curl_exec, but then the second curl_exec seems to be stuck
Try to re-initialize cURL the second time around as well. Or, close the first cURL and re-open cURL before the second block.
The second request seems to working ok, although for some reason I'm not getting what I want, I think I need investigate more, but again your solution is good
-1

Use the 2 options I listed to disable SSL verification temporarily, that might be it (if the certs aren't setup correctly). Note the "CURLOPT_SSL_VERIFYHOST" option. Otherwise I'd just play with the options more. Also you don't have to loop through those values, you can just use an associative array.

<?php
//create array of data to be posted
$post_data['username'] = 'user';
$post_data['password'] = 'log';
$post_data['cmd'] = 'log';

//create cURL connection
$curl_connection = curl_init();
//set options
curl_setopt($curl_connection,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl_connection,CURLOPT_SSL_VERIFYPEER, false);

//...

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_data);//it can accept associative arrays

//...

?>

Comments

-1

After trying the other answers, I was still getting the SSL connection timeout error.

I checked in my php.ini and decided to check if there was anything related to OpenSSL, and I did find that:

;extension=php_openssl.dll

I enabled it by uncommenting the line.

extension=php_openssl.dll

Now, with OpenSSL enabled (this is the parameter on Windows, it should be similar on Linux/Mac) and after restarting my Apache server, I can finally execute my cURL request without any error!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.