0

I'm struggling with this getting errors for either Undefined array key or cannot access offset of type string on string. When I tried to directly access part of the array with like: $results[2]['context'] or $results[0]['dom'] I would get the Cannot access offset of type string on string error. I guess I'm not sure how to access these results either directly or even looped should I need to. Is the way I'm using the curl_multi_* messing up the array?
What am I missing?


<?php
session_start();
$authorization = "Authorization: Bearer ".$_SESSION['toke'];
$domurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'];
$dimurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'] . '/dim';
$conurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'] . '/con';
$lisurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'] . '/lis';
$senurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'] . '/sen';
$nsurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'] . '/ns';
$malurl = 'https://api.xxxx.xx/intel/v4/dom/' . $_POST['domata'] . '/mal/urls';

$requests = array($domurl, $dimurl, $conurl, $lisurl, $senurl, $nsurl, $malurl);
$main    = curl_multi_init();
$results = array();
$errors  = array();
$info = array();
$count = count($requests);
for($i = 0; $i < $count; $i++)
{
$handles[$i] = curl_init($requests[$i]);
//var_dump($requests[$i]);

curl_setopt_array($handles[$i], array(
  CURLOPT_URL => $requests[$i],
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array($authorization),
));

//curl_setopt($handles[$i], CURLOPT_URL, $requests[$i]);
//curl_setopt($handles[$i], CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($main, $handles[$i]);
}
$running = 0;
do {
curl_multi_exec($main, $running);
}
while($running > 0);
for($i = 0; $i < $count; $i++)
{
$results[] = curl_multi_getcontent($handles[$i]);
//$errors[]  = curl_error($handles[$i]);
//$info[]    = curl_getinfo($handles[$i]);
curl_multi_remove_handle($main, $handles[$i]);
}
curl_multi_close($main);
//print_r($results);
//echo implode(" ",$results);
//echo json_encode($results);
var_dump($results);
//var_dump($errors);
echo $requests[0]. " ==><br>";
//echo gettype($results);
//print_r($info[0]);
echo "<br><br>";
echo '<table class="tftable" border="1">';
//if (isset($results['dom'])){
//$domm = $results['dom'];
//echo 'Dom: ' . $domm; }
print_r(array_values($results));
print("<pre>".print_r($results,true)."</pre>");


echo '         <tr>';
echo '            <th colspan=4><center>Dom Info</th></center>';
echo '        </tr>';
echo '        <tr><th>Type</th><th>Value</th><th>Laseen</th></tr>';
echo '            <td>Dom: </td>';
echo '            <td> ' . $results['2']['context'] . '</td> ';
echo '            <td>' . date('m/d/Y H:i', $results['lseen'])  . '</td>';
echo '            </tr>';

//print_r();

the print_r(array_values($results)) gives the following output:

Array ( [0] => {"dom":"biggie.com","lseen":9393789,"ebused":false,"who":{"created":7416583,"expire":7032583,"reg":"Company Solutions, LLC"},"score":144.5} [1] => {"human-test":12.5,"infrared":12} [2] => [{"context":"cert","lseen":393789},{"context":"hello","last-seen":9361558},{"context":"mailbody","lseen":545360},{"context":"sample","lseen":1645360}] [3] => {"ts":9393789,"listed":false} [4] => [{"ip":"314.199.23.133","hello":"biggie.com","lseen":167558,"score":49.6},{"ip":"629.732.363.252","hello":null,"lseen":167360,"score":15.5},{"ip":"49.75.156.214","hello":null,"lseen":167785,"score":191.1}] [5] => [{"ns":"graham.ns.asample.com","lseen":163789,"score":443.0003716,"counting":75},{"ns":"island.ns.potato.com","lseen":13789,"score":333.84,"counting":69}] [6] => [] )

And the <pre version gives:

Array
(
    [0] => {"dom":"biggie.com","lseen":9393789,"ebused":false,"who":{"created":7416583,"expire":7032583,"reg":"Company Solutions, LLC"},"score":144.5}

    [1] => {"human-test":12.5,"infrared":12}

    [2] => [{"context":"cert","lseen":393789},{"context":"hello","last-seen":9361558},{"context":"mailbody","lseen":545360},{"context":"sample","lseen":1645360}]

    [3] => {"ts":9393789,"listed":false}

    [4] => [{"ip":"314.199.23.133","hello":"biggie.com","lseen":167558,"score":49.6},{"ip":"629.732.363.252","hello":null,"lseen":167360,"score":15.5},{"ip":"49.75.156.214","hello":null,"lseen":167785,"score":191.1}]

    [5] => [{"ns":"graham.ns.asample.com","lseen":163789,"score":443.0003716,"counting":75},{"ns":"island.ns.potato.com","lseen":13789,"score":333.84,"counting":69}]

    [6] => []

)

0 Answers0