Hello
I am new to using cURL.
I have two servers. I need to use cURL to POST data from one server to another server than has a form on it.
Server 1 sending to Server 2 form
For now I am simulating this form to capture an email address.
The script indicates no errors when run on server 1 but on the server 2 the processing script for the form is not executed as it is supposed update number of hits. The hit counter is not updated and there is no error indicated on Server 2 error_log as I use PHP error_log to write to the error_log.
If I access the Server 2 form manually it works
Here are my 3 scripts:
Server 2 Form script Called test.php
<?php
?>
<form id=“Form” action=“test_form.php” method=“post”>
<input type="text" name="email_address">
<input type="submit" value="Submit" type="button">
</form>
test_form.php to process test.php
<?php
error_log('POST '. $_POST[‘email_address’],0);
include(‘dbconnect.php’);
$sql_add_submission = “UPDATE asdb1.leaddb SET num_sent = num_sent + 1 WHERE email = '” . $_POST[‘email_address’] . “'”;
$result_add_submission = mysql_query($sql_add_submission);
?>
Server 1 remote submission
<?php
session_start();
//include(‘host_mariadb.php’);
include(‘dbconnect.php’);
$sql_lead = “SELECT * FROM asdb1.leaddb ORDER BY num_sent ASC LIMIT 1”;
$result_lead = mysql_query($sql_lead) OR die(mysql_error() . 'SQL_LEAD ’ . $sql_lead);
$row_lead = mysql_fetch_assoc($result_lead);
$email = $row_lead[‘email’];
$sql_offer = “SELECT * FROM asdb1.offerdb ORDER BY num_submitted ASC LIMIT 1”;
$result_offer = mysql_query($sql_offer) OR die(mysql_error() . 'SQL_OFFER ’ . $sql_offer);
$row_offer = mysql_fetch_assoc($result_offer);
$offer_url = $row_offer[‘offer_url’];
echo “FINISHED<br><br>”;
//create array of data to be posted
$post_data[‘email’] = $email;
//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);
echo " POST STRING " . $post_string . “<br><br>”;
//create cURL connection
$curl_connection = curl_init($offer_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_POST, true);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
echo "Result " . $result . “<br><br>”;
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo "<br><br>Curl ERROR " . curl_errno($curl_connection) . ‘-’ . curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
Output from server 1
FINISHED
POST STRING email=XXXXXXXX@yahoo.com
Result _______________ SUBMIT
Array ( => http://???.com/test.php [content_type] => text/html [http_code] => 200 [header_size] => 151 [request_size] => 238 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.044866 [namelookup_time] => 0.004912 [connect_time] => 0.005052 [pretransfer_time] => 0.005139 [size_upload] => 24 [size_download] => 161 [speed_download] => 3588 [speed_upload] => 534 [download_content_length] => -1 [upload_content_length] => 24 [starttransfer_time] => 0.039989 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => XXX.XXX.XXX.XXX [primary_port] => 80 [local_ip] => XXX.XXX.XXX.XXX [local_port] => 46382 [redirect_url] => )
Curl ERROR 0-
The => http://???.com/test.php is the correct url
Any help will be appreciated