TechAsh
Retired
- Messages
- 5,853
- Reaction score
- 7
- Points
- 38
This code works fine:
It outputs the amount of bandwidth I've used and got left, as well as percentages. It also outputs a nice progress bar type thing.
But this code doesn't work:
This should do exactly the same except it gets the total used bandwidth from a function. However this doesn't work it says that I've not used any of my bandwidth. I've checked that the function is outputting the correct data.
Any suggestions?
It's probably something really obvious, but I'm only a beginner with PHP.
PHP:
function getBandWidth($total) {
$cpanel = new cPanel('*******', '******', '*****', 2083, true, 'x3');
$bu = 156.93;
$bt = $total;
$bf = $bt-$bu;
$percf = $bf/$bt*100;
$percu = $bu/$bt*100;
$outp = round(($percf/100*122)+1, 2);
if ($percu >= 90) {
$color = "#F00";
}
elseif ($percu >= 75) {
$color = "#F90";
}
else {
$color = "#000";
}
echo("<DIV style=\"background-color: " . $color . "\">\n");
echo("<IMG src=\"http://famweb.co.cc/includes/images/percentImage.png\" alt=\"\" class=\"percentImage\" style=\"background-position: -".$outp."px 0pt;\"><BR>\n");
echo("Used: " . round("$percu", 2) . "%<BR>\n");
echo("Used: " . round("$bu", 2) . "MB<BR>\n");
echo("Free: " . round("$percf", 2) . "%<BR>\n");
echo("Free: " . round("$bf", 2) . "MB<BR>\n");
echo("</DIV>\n");
}
But this code doesn't work:
PHP:
function getBandWidth($total) {
$cpanel = new cPanel('******', '****', '******', 2083, true, 'x3');
$bu = $cpanel->getBandwidthUsed(); //<-- This is the only bit that's changed.
$bt = $total;
$bf = $bt-$bu;
$percf = $bf/$bt*100;
$percu = $bu/$bt*100;
$outp = round(($percf/100*122)+1, 2);
if ($percu >= 90) {
$color = "#F00";
}
elseif ($percu >= 75) {
$color = "#F90";
}
else {
$color = "#000";
}
echo("<DIV style=\"background-color: " . $color . "\">\n");
echo("<IMG src=\"http://famweb.co.cc/includes/images/percentImage.png\" alt=\"\" class=\"percentImage\" style=\"background-position: -".$outp."px 0pt;\"><BR>\n");
echo("Used: " . round("$percu", 2) . "%<BR>\n");
echo("Used: " . round("$bu", 2) . "MB<BR>\n");
echo("Free: " . round("$percf", 2) . "%<BR>\n");
echo("Free: " . round("$bf", 2) . "MB<BR>\n");
echo("</DIV>\n");
}
Any suggestions?
It's probably something really obvious, but I'm only a beginner with PHP.
Last edited: