I am creating a plugin that sends a form automatically by using PHP cURL. Its result is good but the form was not posted by the server. Why is that?
//create array of data to be posted
$post_data['full_name'] = $name;
$post_data['email'] = $email;
$post_data['subscription_type'] = 'E';
$post_data['id'] = $id;
//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($target_url);
//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);
This is the result of the code.
Array (
[url] => http://www.remote-server.com/formcapture.php?v=28&w=29
[content_type] => text/html
[http_code] => 200
[header_size] => 180
[request_size] => 302
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.742828
[namelookup_time] => 0.015174
[connect_time] => 0.062791
[pretransfer_time] => 0.0628
[size_upload] => 75
[size_download] => 6122
[speed_download] => 8241
[speed_upload] => 100
[download_content_length] => 6122
[upload_content_length] => 75
[starttransfer_time] => 0.692776
[redirect_time] => 0
) 0-
This is the form that I want to send.
<form class='subscription_form' id='subscription_form' method='POST' action='http://www.remote-server.com/formcapture.php?v=28&w=29'>
<div align='center'><center>
<p>Full name<br><input type='text' name='full_name' size='20'></p>
</center></div>
<div align='center'><center>
<p>E-mail address<br><input type='text' name='email' size='20'></p>
</center></div>
<input type='hidden' name='subscription_type' value='E'><div align='center'><center>
<p><input type='submit' value='Go »'></p>
</center></div>
<input type='hidden' name='id' value='360'>
</form>
Have you tried setting cURL to return the response headers?
This should bring back the headers which you can echo out and use to see what the other server is attually returning.
Also :
Should bring back the HTTP response code e.g 200 404 500 etc