cURL Form Not Responding - Why?

I am trying to use cURL in a form. The form is for a user to enter their telephone number and captcha. Once the form is submitted, the telephone number is sent to an external server and a call is placed between my telephone and the user’s. Something is not right as once the user clicks the ‘Submit’ button, all they see is an Array and the server does not respond by placing the call. Can anyone help and/or see what I may be doing wrong?

The HTML form is as follows:


<html><body>
<form name="form1" method="post" action="callback-3.php"> 
Number: <input name="destination" type="text" size="18" value="Destination"> 
Captcha: <img src="http://www.website.com/captcha" width="200" height="70">
<input name="captcha" type="text" size="5" value="Captcha"> 
<input type="submit" name="Submit" value="Submit"> 
</form>
</body></html>

The “callback-3.php” script is as follows:


<?php
 
//create array of data to be posted
$post_data['destination'] = 'Destination';
$post_data['captcha'] = 'Captcha';
 
//traverse array and prepare data for posting (key1=value1)
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('http://www.website.com/page.php?code=abs123456789');
 
//set options
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
$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);
 
?>

Clicking the ‘Submit’ button results in the following being displayed:


Array (  => http://www.website.com/page.php?code=abs123456789 [content_type] => text/html [http_code] => 200 [header_size] => 432 [request_size] => 266 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.593 [namelookup_time] => 0 [connect_time] => 0.016 [pretransfer_time] => 0.016 [size_upload] => 39 [size_download] => 3153 [speed_download] => 5317 [speed_upload] => 65 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 0.593 [redirect_time] => 0 [certinfo] => Array ( ) ) 0-

Could it be that the form data is not being posted in the format that the external server expects? I do not have access to the “http://www.website.com/page.php?code=abs123456789” file which is on the external server and to which the cURL connection is being made.

Is there a way to post the data in the two HTML fields directly to this php script without placing the data in an array first (which the script on my server is doing)?

I’ve had a further play this evening and have implemented cookie tracking, but this is still not working!

The HTML form is as follows:


<html>
<body>
<?php
//create cURL connection
$curl_connection = curl_init('http://www.website.com/page.php?code=abs123456789');

//get cookies
$curl_connection = curl_init();
$cookie_file_path = 'my_cookie.txt';
$cookie_file_path = realpath($cookie_file_path);

curl_setopt($curl_connection, CURLOPT_COOKIESESSION, true); 
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $cookie_file_path);

//cURL options
curl_setopt($curl_connection, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//new ones
curl_setopt($curl_connection, CURLOPT_HEADER, 1);
curl_setopt($curl_connection, CURLOPT_URL,"http://www.website.com/page.php?code=abs123456789");

?>

<form name="form1" method="post" action="callback-3.php"> 
Number: <input name="destination" type="text" size="18" value=""> 
Captcha: <img src="

<?php
// get captcha image
include ('simple_html_dom.php');

$html = file_get_html('http://www.website.com/page.php?code=abs123456789');

foreach($html->find('fieldset img') as $element)
       echo 'http://www.website.co.uk' . $element->src;

?>


" width="200" height="70">
<input name="captcha" type="text" size="5" value=""> 
<input type="submit" name="Submit" value="Call"> 
</form>
</body></html>

The “callback.php” script as per the form’s ‘action’ target is as follows:


<?php
//create array of data to be posted
$post_data['destination'] = '';
$post_data['captcha'] = '';
 
//traverse array and prepare data for posting (key1=value1)
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('http://www.website.com/page.php?code=abs123456789');
 
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_VERBOSE, TRUE);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
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_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);
 
?>

Anyone able to spare some time and help me out please :)?

Can no one honestly help?