1

Deepcrawl.php

<?php 

$array_issues[] = 0;

$issues = array("thin_pages_basic","not_in_sitemaps_primary_indexable_basic","duplicate_titles_2_basic","pages_with_duplicate_titles_basic","max_external_links_basic","4xx_errors_basic");

for($i=0;$i<6;$i++){
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"Your Api key". $issues[$i]);

curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token:91PB_EP-LSaTVcm2bCjWyE9oLBEhGYSpvuW-gILR1eCEiK-VPL4YO40L8hTFTnepC8HjaLgn2C3AG6k3iv_-zg'));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output2 = curl_exec ($ch);
curl_close ($ch); 

$results = json_decode($server_output2);

$j=0;
// to get each object from an array of object
foreach((array)$results as $result){ 
  if($j==3)
  $array_issues[$i] = $result;

  $j++;
  }
} 
?>

Displaying in the view file

                 <tr>
                    <td style='color:#e86363'>" . $array_issues[0] . "</td>
                    <td style='width:50px'></td>
                    <td>Thin Pages</td>
                </tr>
                 <tr>
                    <td style='color:#e86363'>" . $array_issues[1] . "</td>
                    <td style='width:50px'></td>
                    <td>Primary Indexable Pages Not in Sitemaps </td>
                </tr>
                 <tr>
                    <td style='color:#e86363'>" . $array_issues[2] . "</td>
                    <td style='width:50px'></td>
                    <td>Duplicate Title Sets</td>
                </tr>
                 <tr>
                    <td style='color:#e86363'>" . $array_issues[3] . "</td>
                    <td style='width:50px'></td>
                    <td>Pages with Duplicate Titles</td>
                </tr>
                 <tr>
                    <td style='color:#e86363'>" . $array_issues[4] . "</td>
                    <td style='width:50px'></td>
                    <td>High External Linking</td>
                </tr>
                 <tr>
                    <td style='color:#e86363'>" . $array_issues[5] . "</td>
                    <td style='width:50px'></td>
                    <td>Broken Pages (4xx Errors)</td>
                </tr>

Just wondering when I'm declaring on my view file I always got this error Undefined offset: 1

But when I change the array from [1-5] to [0] it works okay but it didn't get any data at all? If you see whats causing this, posting below would really help. Thanks! :)

Christian Gallarmin
  • 660
  • 4
  • 15
  • 34
  • What do you get if you `var_dump($array_issues);`? – aynber Sep 12 '18 at 17:04
  • 1
    It seems you meant to replace your auth token with an abstraction, but you've actually replaced your URL and left your token in place. You probably want to change/revoke that token immediately. – Alex Howansky Sep 12 '18 at 17:09
  • 1
    Print your array and check array having actually offsets that you are accessing –  Sep 12 '18 at 17:10
  • @AlexHowansky I just need to hide my api key. that's why I leave my auth token out there. But thank you for reminding me. – Christian Gallarmin Sep 12 '18 at 18:06
  • Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – miken32 Sep 12 '18 at 18:07
  • array(6) { [0]=> string(0) "" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" [4]=> string(0) "" [5]=> string(0) "" } @aynber – Christian Gallarmin Sep 12 '18 at 18:43

1 Answers1

1

First of all, change your $array_issues declaration to either

$array_issues = array(); 

or

$array_issues = [];

Then, i don't know what you are trying to accomplish in this lines:

$results = json_decode($server_output2);

$j=0;
// to get each object from an array of object
foreach((array)$results as $result){ 
    if($j==3)
    $array_issues[$i] = $result;

    $j++;
}

But, i don't think this is initializing your $array_issues[0] index correctly, it may not even be entering this... i would at least initialize the index outside that if and foreach, something like:

$j=0;
// to get each object from an array of object
$array_issues[$i] = ""; // MAKING SURE THIS IS AT LEAST DEFINED.
foreach((array)$results as $result){ 
    if($j==3)
    $array_issues[$i] = $result;

    $j++;
}

Also, i think you could accomplish what you are trying to do with a $key => $value syntax instead of that $j counter...

$array_issues[$i] = ""; // MAKING SURE THIS IS AT LEAST DEFINED.
foreach((array)$results as $key => $result){ 
    if($key==3)
    $array_issues[$i] = $result;
}
Erubiel
  • 2,934
  • 14
  • 32