ban ban - 8 days ago 6
JSON Question

is it possible to have two curl_init

hi ive been trying to run this code but iam getting page isn't working not even an error can somoene point me to the right direction? thanks

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://security.voluum.com/login");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");


$headers = array();
$headers[] = "Authorization: Basic plFubTHhcl93MzA4QHJJkQ9vqmNvwTpMNYYUIz5kcm9s";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$res_decoded = json_decode($result);
echo $res_decoded->token;
$tok = $res_decoded->token;

$sh = curl_init();
curl_setopt($sh, CURLOPT_URL, "https://reports.voluum.com/report?from=2016-11-24T00%3A00%3A00Z&to=2016-11-26T00%3A00%3A00Z&tz=Europe%2FWarsaw&sort=visits&direction=desc&columns=campaignName&columns=visits&columns=clicks&columns=conversions&columns=revenue&columns=cost&columns=profit&columns=cpv&columns=ctr&columns=cr&columns=cv&columns=roi&columns=epv&columns=epc&columns=ap&columns=errors&groupBy=campaign&offset=0&limit=100&include=active");
curl_setopt($sh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($sh, CURLOPT_CUSTOMREQUEST, "GET");


$header = array();
$header[] = "Cwauth-Token: " . $tok;
curl_setopt($, CURLOPT_HTTPHEADER, $headers);

$results = curl_exec($sh);
if (curl_errno($sh)) {
echo 'Error:' . curl_error($sh);
}

echo $results;
curl_close ($ch);
curl_close ($sh);
?>


every time the page refreshes the token changes so i need to put a dynamic token in the second header. i don't know if i'am doing the right thing here

Answer

Take a look at this: http://us2.php.net/manual/en/function.curl-multi-exec.php

Maybe this will help you.

Comments