This code should pull from a JSON file, and display the values in a table, looping for each IP instance the API returns. Instead of displaying the entries in the table, I'm just getting a blank table. Any ideas?
This is using the Vultr API, and I masked my SUBID and API Key with X's, if you're wondering what that is. I know this method works, as I used it before with the same API. My theory is that my problem is stemming from the JSON being returned with the [].
I have the following JSON coming in:
{"30953157":[{"ip":"207.148.0.160","netmask":"255.255.254.0","gateway":"207.148.0.1","type":"main_ip","reverse":"brazos.cwservernetwork.com"},{"ip":"144.202.69.201","netmask":"255.255.254.0","gateway":"144.202.68.1","type":"secondary_ip","reverse":"brazos.cwservernetwork.com"}]}
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>List IP</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>
<body>
<table width="1800px">
<tr>
<td colspan="6"><h1><b><u>Listing IPv4</h1></u></b></td>
</tr>
<tr>
<td style="text-align:center"><b>IPv4</b></td>
<td style="text-align:center"><b>Netmask</b></td>
<td style="text-align:center"><b>Gateway</b></td>
<td style="text-align:center"><b>Type</b></td>
<td style="text-align:center"><b>Reverse</b></td>
</tr>
<?php
$myVultrApiKey="XXXXXXXXXXXXXXXXXXXXXX";
$loadingtime = time();
$json = file_get_contents("https://api.vultr.com/v1/server/list_ipv4?api_key=$myVultrApiKey&SUBID=XXXXXXXXX");
$data = json_decode($json);
print $json;
foreach ($data as $name => $value)
{
?>
<tr>
<td style="text-align:center"><?php echo $value->ip; ?></td>
<td style="text-align:center"><?php echo $value->netmask; ?></td>
<td style="text-align:center"><?php echo $value->gateway; ?></td>
<td style="text-align:center"><?php echo $value->type; ?></td>
<td style="text-align:center"><?php echo $value->reverse; ?></td>
<?php
}//end for
?>
</tr>
<tr>
<td colspan="2">
<br><br><br><br><br>
<?php echo "Load Time: " . "<font color=\"green\">" . (time() - $loadingtime) . "s </font><br />\n"; ?>
</td>
</tr>
</table>
</body>
</html>