“;
echo “pls install curl\n”;
echo “For *unix open terminal and type this:\n”;
echo ‘sudo apt-get install curl && apt-get install php-curl’;
die;
}
if ($_SERVER[‘REQUEST_METHOD’] === ‘POST’) {
// Check if the fields are not filled in reject and do not send anything
if (empty($_POST[NAME_FIELD]) || empty($_POST[PHONE_FIELD])) {
header(‘Location: ‘.$urlForEmptyRequiredFields);
exit;
}
$args = array(
‘name’ => $_POST[NAME_FIELD],
‘phone’ => $_POST[PHONE_FIELD],
‘offerId’ => OFFER_ID,
‘domain’ => “http://” . $_SERVER[“HTTP_HOST”] . $_SERVER[“REQUEST_URI”],
‘ip’ => getUserIp(),
‘utm_campaign’ => key_exists(‘utm_campaign’, $_POST) ? $_POST[‘utm_campaign’] : null,
‘utm_content’ => key_exists(‘utm_content’, $_POST) ? $_POST[‘utm_content’] : null,
‘utm_medium’ => key_exists(‘utm_medium’, $_POST) ? $_POST[‘utm_medium’] : null,
‘utm_source’ => key_exists(‘utm_source’, $_POST) ? $_POST[‘utm_source’] : null,
‘utm_term’ => key_exists(‘utm_term’, $_POST) ? $_POST[‘utm_term’] : null,
‘clickid’ => key_exists(‘clickid’, $_POST) ? $_POST[‘clickid’] : null,
‘fbpxl’ => key_exists(‘fbpxl’, $_POST) ? $_POST[‘fbpxl’] : null,
‘cost’ => COST,
);
$data = json_encode($args);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => API_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
‘Content-Type: application/json’,
‘Content-Length: ‘ . strlen($data),
‘X-Token: ‘.WEBMASTER_TOKEN,
),
));
$result = curl_exec($curl);
curl_close($curl);
writeToLog($args, $result);
$result = json_decode($result, true);
if ($result === null) {
header(‘Location: ‘.$urlForEmptyRequiredFields);
exit;
} else {
$parameters = [
‘fbpxl’ => $args[‘fbpxl’],
‘fio’ => $args[‘name’],
‘name’ => $args[‘name’],
‘phone’ => $args[‘phone’]
];
$urlSuccess .= ‘?’ . http_build_query($parameters);
header(‘Location: ‘.$urlSuccess);
exit;
}
}
?>