I seem to have run into a problem with trying to submit form variables to multiple urls. The code i have below takes variables from a form and stores them in php, then I am trying to send those variables to certain urls (the variables do pass through, I've tested that). I heard cUrl is the way to do it, but I don't know if its working cause im stumped on how to to retrieve the response code.
<?php
$name = $_POST['firstname'];
$email = $_POST['email'];
$src = $_POST['srcUrl'];
$ip= $_SERVER['SERVER_ADDR'];
$suDate = date('Y-m-d H:i:s');
$data = array(
"fn" => $name,
"src" => $src,
"em" => $email,
"ip" => $ip,
"signupDate" => $suDate
);
$data2 = array(
"firstname" => $name,
"email" => $email,
);
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
curl_close($post);
}
post_to_url("http://exampleURL.com/page.php", $data);
post_to_url("http://exampleURL2.com/cgi-bin/add.cgi", $data2);
print_r($result);
?>
any help is greatly appreciated. thanks