MDauphinais1
asked on
Not displaying all data
I have a script (below) that lists all of the shoutcast servers that I am using as well as their stats. There is one portion of the script that isn't working right. The part where it is suppose to display the countries from which users are connected, I can't tell what it is doing but it isn't displaying everything. It is either only displaying the first entry for each server or it is taking the first three entries from the first server and splitting them up between the three servers displayed.
Here is the script in action: http://www.emphaticradio.com/serverstatus.php
The number of countries for each server should match the number of listeners on that server.
Any help would be much appreciated.
//////SCRIPT//////
<?
/* ---------- General configuration ---------- */
/*
$RCSfile: status.php,v $
$Revision: 1.34 $
$module_name = basename(dirname(__FILE__) );
require("geostats/shoutcas t.class.ph ps");
require("geostats/geoip.ph ps");
$index = 1;
is_readable("geostats/GeoI P.dat") or exit("Error: GeoIP.dat not found!");
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
$listenersArray["Total"][" current"] = 0;
$listenersArray["Total"][" max"] = 0;
$station_name = "Emphatic Radio.com!";
$refresh = "60"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
/* -------------------------- ---------- ------- */
$servers = count($ip);
?>
<?
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$ i],$errno, $errstr,$t imeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head> <body>', "", $info);
$info = str_replace('</body></html >', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span><p><b>List ener peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
$total_slots = array_sum($max) ;
$availableslots = ($total_slots-$total_liste ners);
print "<div id=\"blu\">\n <div style=\"text-align: center;\">\n <font size=\"4\">\nThere are $total_listeners listeners locked <br> $availableslots available slots remaining
</font>\n </div>\n</div>\n<div>\n <div>\n <p><b>Current song:</b> $song[1]</p>\n </div>\n</div>\n<div>\n";
$i = "1";
while($i<=$servers)
{
print " <div>\n";
if ($max[$i] > 0)
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] = 1)
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"><img src="images/<? if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<? print $barlength ?>" height="12" alt="The server is at <? print $percentage; ?>% capacity"></td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
else
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"> </ td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
$fp = @fsockopen($ip[$i],$port[$ i],$errno, $errstr,$t imeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head> <body>', "", $info);
$info = str_replace('</body></html >', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$gi = geoip_open("geostats/GeoIP .dat", GEOIP_STANDARD);
for ($count = 0;$count < count($servers); $count++) {
$shoutcast = new ShoutCast();
$shoutcast->name = $location[$i];
$shoutcast->host = $ip[$i];
$shoutcast->port = $port[$i];
$shoutcast->passwd = $password[$i];
$listenersArray["$shoutcas t->name"][ "current"] = "NA";
$listenersArray["$shoutcas t->name"][ "max"] = "NA";
if ($shoutcast->openstats()) {
// We got the XML, gogogo!..
if ($shoutcast->GetStreamStat us()) {
$listenersArray["$shoutcas t->name"][ "current"] = $shoutcast->GetCurrentList enersCount ();
$listenersArray["$shoutcas t->name"][ "max"] = $shoutcast->GetMaxListener sCount();
$listenersArray["Total"][" current"] += $shoutcast->GetCurrentList enersCount ();
$listenersArray["Total"][" max"] += $shoutcast->GetMaxListener sCount();
$listeners_geo = $shoutcast->GetListeners() ;
if (is_array($listeners_geo)) {
for ($is=0;$is<sizeof($listene rs_geo);$i s++) {
$country_id = geoip_country_id_by_name($ gi, $listeners_geo[$is]["hostn ame"]);
$country_name = $GLOBALS['GEOIP_COUNTRY_NA MES'][$cou ntry_id];
if (!$country_id) {
$country_id = 0;
$country_name = "Earth(unidentified)";
}
$from["$country_id"]++;
}
} else {
echo "
Noone listens right now..
\n";
}
echo " \n";
} else {
echo "Server is up, but no stream available..
\n";
}
} else {
// Ohhh, damnit..
echo $shoutcast->geterror();
echo "\n \n \n";
}
echo " \n";
$count++;
}
geoip_close($gi);
?>
<br>
<table border=\"1\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" align="center">
<tr>
<td>Flag</td>
<td>Country</td>
<td>Listeners</td>
</tr>
<tr>
<?php
arsort($from);
reset($from);
while (list($key, $val) = each($from)) {
$country_code = $GLOBALS['GEOIP_COUNTRY_CO DES']["$ke y"];
$country_name = $GLOBALS['GEOIP_COUNTRY_NA MES']["$ke y"];
if (!$country_code) {
if (!$key && $key != 0) {
$country_code = $key;
} else {
// I don't want to show unidentified hosts in ranking.
// $country_code = "N/A";
continue;
}
}
echo"<td><img src=\"geostats/$country_co de.GIF\" alt=\"flag of the $country_name\" /></td><td>$country_name</ td>
<td> $val</td></tr></table>
\n";
$countrycount++;
if ($countrycount >= $countrylimit) break;
}
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span>
<br>
<br>
<b>Web Hits:</b> ".$shoutcast->GetWebHitsCo unt()."<br /> <b>Stream Hits:</b> ".$shoutcast->GetStreamHit sCount()." <br /> <b>Average Listen Time:</b> ".elapsedtime($shoutcast-> GetAverage ListenTime ())."
<p><b>Listener Peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
print " <p><b>Status:</b> $msg[$i]</p>\n </div>\n <div class=\"line\"> </div>\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("h:ia", time() + $time_difference);
$date = date("jS F, Y", time() + 0);
print "<div>\n <div>\n <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n </div>\n</div>\n";
?>
<div>
<div>
Here is the script in action: http://www.emphaticradio.com/serverstatus.php
The number of countries for each server should match the number of listeners on that server.
Any help would be much appreciated.
//////SCRIPT//////
<?
/* ---------- General configuration ---------- */
/*
$RCSfile: status.php,v $
$Revision: 1.34 $
$module_name = basename(dirname(__FILE__)
require("geostats/shoutcas
require("geostats/geoip.ph
$index = 1;
is_readable("geostats/GeoI
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
$listenersArray["Total"]["
$listenersArray["Total"]["
$station_name = "Emphatic Radio.com!";
$refresh = "60"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
/* --------------------------
$servers = count($ip);
?>
<?
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head>
$info = str_replace('</body></html
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span><p><b>List
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
$total_slots = array_sum($max) ;
$availableslots = ($total_slots-$total_liste
print "<div id=\"blu\">\n <div style=\"text-align: center;\">\n <font size=\"4\">\nThere are $total_listeners listeners locked <br> $availableslots available slots remaining
</font>\n </div>\n</div>\n<div>\n <div>\n <p><b>Current song:</b> $song[1]</p>\n </div>\n</div>\n<div>\n";
$i = "1";
while($i<=$servers)
{
print " <div>\n";
if ($max[$i] > 0)
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] = 1)
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"><img src="images/<? if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<? print $barlength ?>" height="12" alt="The server is at <? print $percentage; ?>% capacity"></td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
else
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"> </
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
$fp = @fsockopen($ip[$i],$port[$
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head>
$info = str_replace('</body></html
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$gi = geoip_open("geostats/GeoIP
for ($count = 0;$count < count($servers); $count++) {
$shoutcast = new ShoutCast();
$shoutcast->name = $location[$i];
$shoutcast->host = $ip[$i];
$shoutcast->port = $port[$i];
$shoutcast->passwd = $password[$i];
$listenersArray["$shoutcas
$listenersArray["$shoutcas
if ($shoutcast->openstats()) {
// We got the XML, gogogo!..
if ($shoutcast->GetStreamStat
$listenersArray["$shoutcas
$listenersArray["$shoutcas
$listenersArray["Total"]["
$listenersArray["Total"]["
$listeners_geo = $shoutcast->GetListeners()
if (is_array($listeners_geo))
for ($is=0;$is<sizeof($listene
$country_id = geoip_country_id_by_name($
$country_name = $GLOBALS['GEOIP_COUNTRY_NA
if (!$country_id) {
$country_id = 0;
$country_name = "Earth(unidentified)";
}
$from["$country_id"]++;
}
} else {
echo "
Noone listens right now..
\n";
}
echo " \n";
} else {
echo "Server is up, but no stream available..
\n";
}
} else {
// Ohhh, damnit..
echo $shoutcast->geterror();
echo "\n \n \n";
}
echo " \n";
$count++;
}
geoip_close($gi);
?>
<br>
<table border=\"1\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" align="center">
<tr>
<td>Flag</td>
<td>Country</td>
<td>Listeners</td>
</tr>
<tr>
<?php
arsort($from);
reset($from);
while (list($key, $val) = each($from)) {
$country_code = $GLOBALS['GEOIP_COUNTRY_CO
$country_name = $GLOBALS['GEOIP_COUNTRY_NA
if (!$country_code) {
if (!$key && $key != 0) {
$country_code = $key;
} else {
// I don't want to show unidentified hosts in ranking.
// $country_code = "N/A";
continue;
}
}
echo"<td><img src=\"geostats/$country_co
<td> $val</td></tr></table>
\n";
$countrycount++;
if ($countrycount >= $countrylimit) break;
}
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span>
<br>
<br>
<b>Web Hits:</b> ".$shoutcast->GetWebHitsCo
<p><b>Listener Peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
print " <p><b>Status:</b> $msg[$i]</p>\n </div>\n <div class=\"line\"> </div>\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("h:ia", time() + $time_difference);
$date = date("jS F, Y", time() + 0);
print "<div>\n <div>\n <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n </div>\n</div>\n";
?>
<div>
<div>
ASKER
There should be 3.
The server stats (the bar that displays the percentage of users), number of users is correct.
The part that is problematic is the table under the percentage bar where it shows the country flag, country name and number of listeners from that country for each server. It doesn't add up. It should show countries for every user connected to that server but it doesn't. It is either only displaying the first entry for each server or it is taking the first three entries from the first server and splitting them up between the three servers displayed. I'm not sure which but it doesn't add up.
The server stats (the bar that displays the percentage of users), number of users is correct.
The part that is problematic is the table under the percentage bar where it shows the country flag, country name and number of listeners from that country for each server. It doesn't add up. It should show countries for every user connected to that server but it doesn't. It is either only displaying the first entry for each server or it is taking the first three entries from the first server and splitting them up between the three servers displayed. I'm not sure which but it doesn't add up.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, changing that it is definately starting to look better. But if you check out that page again the listener count under the countries doesn't equal where is says Status: there are x number of listeners...
ASKER
It almost looks like it is taking the countries from Server 1 and then adding them to Server 2 so Server 2 is actually displaying the countries from Server 1 and 2. And then Server 3 is showing the countries from all 3 instead of just the ones from Server 3.
try like this ....
<?
/* ---------- General configuration ---------- */
/*
$RCSfile: status.php,v $
$Revision: 1.34 $
$module_name = basename(dirname(__FILE__) );
require("geostats/shoutcas t.class.ph ps");
require("geostats/geoip.ph ps");
$index = 1;
is_readable("geostats/GeoI P.dat") or exit("Error: GeoIP.dat not found!");
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
$listenersArray["Total"][" current"] = 0;
$listenersArray["Total"][" max"] = 0;
$station_name = "Emphatic Radio.com!";
$refresh = "60"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
/* -------------------------- ---------- ------- */
$servers = count($ip);
?>
<?
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$ i],$errno, $errstr,$t imeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head> <body>', "", $info);
$info = str_replace('</body></html >', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span><p><b>List ener peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
$total_slots = array_sum($max) ;
$availableslots = ($total_slots-$total_liste ners);
print "<div id=\"blu\">\n <div style=\"text-align: center;\">\n <font size=\"4\">\nThere are $total_listeners listeners locked <br> $availableslots available slots remaining
</font>\n </div>\n</div>\n<div>\n <div>\n <p><b>Current song:</b> $song[1]</p>\n </div>\n</div>\n<div>\n";
$i = "1";
while($i<=$servers)
{
print " <div>\n";
if ($max[$i] > 0)
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] = 1)
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"><img src="images/<? if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<? print $barlength ?>" height="12" alt="The server is at <? print $percentage; ?>% capacity"></td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
else
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"> </ td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
$fp = @fsockopen($ip[$i],$port[$ i],$errno, $errstr,$t imeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head> <body>', "", $info);
$info = str_replace('</body></html >', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$gi = geoip_open("geostats/GeoIP .dat", GEOIP_STANDARD);
for ($count = 0;$count < count($servers); $count++) {
$shoutcast = new ShoutCast();
$shoutcast->name = $location[$i];
$shoutcast->host = $ip[$i];
$shoutcast->port = $port[$i];
$shoutcast->passwd = $password[$i];
$listenersArray["$shoutcas t->name"][ "current"] = "NA";
$listenersArray["$shoutcas t->name"][ "max"] = "NA";
if ($shoutcast->openstats()) {
// We got the XML, gogogo!..
if ($shoutcast->GetStreamStat us()) {
$listenersArray["$shoutcas t->name"][ "current"] = $shoutcast->GetCurrentList enersCount ();
$listenersArray["$shoutcas t->name"][ "max"] = $shoutcast->GetMaxListener sCount();
$listenersArray["Total"][" current"] += $shoutcast->GetCurrentList enersCount ();
$listenersArray["Total"][" max"] += $shoutcast->GetMaxListener sCount();
$listeners_geo = $shoutcast->GetListeners() ;
if (is_array($listeners_geo)) {
for ($is=0;$is<sizeof($listene rs_geo);$i s++) {
$country_id = geoip_country_id_by_name($ gi, $listeners_geo[$is]["hostn ame"]);
$country_name = $GLOBALS['GEOIP_COUNTRY_NA MES'][$cou ntry_id];
if (!$country_id) {
$country_id = 0;
$country_name = "Earth(unidentified)";
}
$from[$i]["$country_id"]++ ;
}
} else {
echo "
Noone listens right now..
\n";
}
echo " \n";
} else {
echo "Server is up, but no stream available..
\n";
}
} else {
// Ohhh, damnit..
echo $shoutcast->geterror();
echo "\n \n \n";
}
echo " \n";
$count++;
}
geoip_close($gi);
?>
<br>
<table border=\"1\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" align="center">
<tr>
<td>Flag</td>
<td>Country</td>
<td>Listeners</td>
</tr>
<tr>
<?php
arsort($from[$i]);
reset($from[$i]);
while (list($key, $val) = each($from[$i])) {
$country_code = $GLOBALS['GEOIP_COUNTRY_CO DES']["$ke y"];
$country_name = $GLOBALS['GEOIP_COUNTRY_NA MES']["$ke y"];
if (!$country_code) {
if (!$key && $key != 0) {
$country_code = $key;
} else {
// I don't want to show unidentified hosts in ranking.
// $country_code = "N/A";
continue;
}
}
echo"<td><img src=\"geostats/$country_co de.GIF\" alt=\"flag of the $country_name\" /></td><td>$country_name</ td>
<td> $val</td></tr></table>
\n";
$countrycount++;
if ($countrycount >= $countrylimit) break;
}
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span>
<br>
<br>
<b>Web Hits:</b> ".$shoutcast->GetWebHitsCo unt()."<br /> <b>Stream Hits:</b> ".$shoutcast->GetStreamHit sCount()." <br /> <b>Average Listen Time:</b> ".elapsedtime($shoutcast-> GetAverage ListenTime ())."
<p><b>Listener Peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
print " <p><b>Status:</b> $msg[$i]</p>\n </div>\n <div class=\"line\"> </div>\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("h:ia", time() + $time_difference);
$date = date("jS F, Y", time() + 0);
print "<div>\n <div>\n <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n </div>\n</div>\n";
?>
<div>
<div>
<?
/* ---------- General configuration ---------- */
/*
$RCSfile: status.php,v $
$Revision: 1.34 $
$module_name = basename(dirname(__FILE__)
require("geostats/shoutcas
require("geostats/geoip.ph
$index = 1;
is_readable("geostats/GeoI
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
$listenersArray["Total"]["
$listenersArray["Total"]["
$station_name = "Emphatic Radio.com!";
$refresh = "60"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
/* --------------------------
$servers = count($ip);
?>
<?
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head>
$info = str_replace('</body></html
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span><p><b>List
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
$total_slots = array_sum($max) ;
$availableslots = ($total_slots-$total_liste
print "<div id=\"blu\">\n <div style=\"text-align: center;\">\n <font size=\"4\">\nThere are $total_listeners listeners locked <br> $availableslots available slots remaining
</font>\n </div>\n</div>\n<div>\n <div>\n <p><b>Current song:</b> $song[1]</p>\n </div>\n</div>\n<div>\n";
$i = "1";
while($i<=$servers)
{
print " <div>\n";
if ($max[$i] > 0)
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] = 1)
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"><img src="images/<? if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<? print $barlength ?>" height="12" alt="The server is at <? print $percentage; ?>% capacity"></td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
else
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"> </
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
$fp = @fsockopen($ip[$i],$port[$
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head>
$info = str_replace('</body></html
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$gi = geoip_open("geostats/GeoIP
for ($count = 0;$count < count($servers); $count++) {
$shoutcast = new ShoutCast();
$shoutcast->name = $location[$i];
$shoutcast->host = $ip[$i];
$shoutcast->port = $port[$i];
$shoutcast->passwd = $password[$i];
$listenersArray["$shoutcas
$listenersArray["$shoutcas
if ($shoutcast->openstats()) {
// We got the XML, gogogo!..
if ($shoutcast->GetStreamStat
$listenersArray["$shoutcas
$listenersArray["$shoutcas
$listenersArray["Total"]["
$listenersArray["Total"]["
$listeners_geo = $shoutcast->GetListeners()
if (is_array($listeners_geo))
for ($is=0;$is<sizeof($listene
$country_id = geoip_country_id_by_name($
$country_name = $GLOBALS['GEOIP_COUNTRY_NA
if (!$country_id) {
$country_id = 0;
$country_name = "Earth(unidentified)";
}
$from[$i]["$country_id"]++
}
} else {
echo "
Noone listens right now..
\n";
}
echo " \n";
} else {
echo "Server is up, but no stream available..
\n";
}
} else {
// Ohhh, damnit..
echo $shoutcast->geterror();
echo "\n \n \n";
}
echo " \n";
$count++;
}
geoip_close($gi);
?>
<br>
<table border=\"1\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" align="center">
<tr>
<td>Flag</td>
<td>Country</td>
<td>Listeners</td>
</tr>
<tr>
<?php
arsort($from[$i]);
reset($from[$i]);
while (list($key, $val) = each($from[$i])) {
$country_code = $GLOBALS['GEOIP_COUNTRY_CO
$country_name = $GLOBALS['GEOIP_COUNTRY_NA
if (!$country_code) {
if (!$key && $key != 0) {
$country_code = $key;
} else {
// I don't want to show unidentified hosts in ranking.
// $country_code = "N/A";
continue;
}
}
echo"<td><img src=\"geostats/$country_co
<td> $val</td></tr></table>
\n";
$countrycount++;
if ($countrycount >= $countrylimit) break;
}
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span>
<br>
<br>
<b>Web Hits:</b> ".$shoutcast->GetWebHitsCo
<p><b>Listener Peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
print " <p><b>Status:</b> $msg[$i]</p>\n </div>\n <div class=\"line\"> </div>\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("h:ia", time() + $time_difference);
$date = date("jS F, Y", time() + 0);
print "<div>\n <div>\n <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n </div>\n</div>\n";
?>
<div>
<div>
ASKER
The page doesn't even load now. It just goes completely blank.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?
/* ---------- General configuration ---------- */
/*
$RCSfile: status.php,v $
$Revision: 1.34 $
$module_name = basename(dirname(__FILE__) );
require("geostats/shoutcas t.class.ph ps");
require("geostats/geoip.ph ps");
$index = 1;
is_readable("geostats/GeoI P.dat") or exit("Error: GeoIP.dat not found!");
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
$listenersArray["Total"][" current"] = 0;
$listenersArray["Total"][" max"] = 0;
$station_name = "Emphatic Radio.com!";
$refresh = "60"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
/* -------------------------- ---------- ------- */
$servers = count($ip);
?>
<?
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$ i],$errno, $errstr,$t imeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head> <body>', "", $info);
$info = str_replace('</body></html >', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span><p><b>List ener peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
$total_slots = array_sum($max) ;
$availableslots = ($total_slots-$total_liste ners);
print "<div id=\"blu\">\n <div style=\"text-align: center;\">\n <font size=\"4\">\nThere are $total_listeners listeners locked <br> $availableslots available slots remaining
</font>\n </div>\n</div>\n<div>\n <div>\n <p><b>Current song:</b> $song[1]</p>\n </div>\n</div>\n<div>\n";
$i = "1";
while($i<=$servers)
{
print " <div>\n";
if ($max[$i] > 0)
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] = 1)
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"><img src="images/<? if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<? print $barlength ?>" height="12" alt="The server is at <? print $percentage; ?>% capacity"></td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
else
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"> </ td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
$fp = @fsockopen($ip[$i],$port[$ i],$errno, $errstr,$t imeout);
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head> <body>', "", $info);
$info = str_replace('</body></html >', "", $info);
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$gi = geoip_open("geostats/GeoIP .dat", GEOIP_STANDARD);
for ($count = 0;$count < count($servers); $count++) {
$shoutcast = new ShoutCast();
$shoutcast->name = $location[$i];
$shoutcast->host = $ip[$i];
$shoutcast->port = $port[$i];
$shoutcast->passwd = $password[$i];
$listenersArray["$shoutcas t->name"][ "current"] = "NA";
$listenersArray["$shoutcas t->name"][ "max"] = "NA";
if ($shoutcast->openstats()) {
// We got the XML, gogogo!..
unset($from);
if ($shoutcast->GetStreamStat us()) {
$listenersArray["$shoutcas t->name"][ "current"] = $shoutcast->GetCurrentList enersCount ();
$listenersArray["$shoutcas t->name"][ "max"] = $shoutcast->GetMaxListener sCount();
$listenersArray["Total"][" current"] += $shoutcast->GetCurrentList enersCount ();
$listenersArray["Total"][" max"] += $shoutcast->GetMaxListener sCount();
$listeners_geo = $shoutcast->GetListeners() ;
if (is_array($listeners_geo)) {
for ($is=0;$is<sizeof($listene rs_geo);$i s++) {
$country_id = geoip_country_id_by_name($ gi, $listeners_geo[$is]["hostn ame"]);
$country_name = $GLOBALS['GEOIP_COUNTRY_NA MES'][$cou ntry_id];
if (!$country_id) {
$country_id = 0;
$country_name = "Earth(unidentified)";
}
$from["$country_id"]++;
}
} else {
echo "
Noone listens right now..
\n";
}
echo " \n";
} else {
echo "Server is up, but no stream available..
\n";
}
} else {
// Ohhh, damnit..
echo $shoutcast->geterror();
echo "\n \n \n";
}
echo " \n";
$count++;
}
geoip_close($gi);
?>
<br>
<table border=\"1\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" align="center">
<tr>
<td>Flag</td>
<td>Country</td>
<td>Listeners</td>
</tr>
<tr>
<?php
arsort($from);
reset($from);
while (list($key, $val) = each($from)) {
$country_code = $GLOBALS['GEOIP_COUNTRY_CO DES']["$ke y"];
$country_name = $GLOBALS['GEOIP_COUNTRY_NA MES']["$ke y"];
if (!$country_code) {
if (!$key && $key != 0) {
$country_code = $key;
} else {
// I don't want to show unidentified hosts in ranking.
// $country_code = "N/A";
continue;
}
}
echo"<td><img src=\"geostats/$country_co de.GIF\" alt=\"flag of the $country_name\" /></td><td>$country_name</ td>
<td> $val</td></tr></table>
\n";
$countrycount++;
if ($countrycount >= $countrylimit) break;
}
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span>
<br>
<br>
<b>Web Hits:</b> ".$shoutcast->GetWebHitsCo unt()."<br /> <b>Stream Hits:</b> ".$shoutcast->GetStreamHit sCount()." <br /> <b>Average Listen Time:</b> ".elapsedtime($shoutcast-> GetAverage ListenTime ())."
<p><b>Listener Peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
print " <p><b>Status:</b> $msg[$i]</p>\n </div>\n <div class=\"line\"> </div>\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("h:ia", time() + $time_difference);
$date = date("jS F, Y", time() + 0);
print "<div>\n <div>\n <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n </div>\n</div>\n";
?>
<div>
<div>
/* ---------- General configuration ---------- */
/*
$RCSfile: status.php,v $
$Revision: 1.34 $
$module_name = basename(dirname(__FILE__)
require("geostats/shoutcas
require("geostats/geoip.ph
$index = 1;
is_readable("geostats/GeoI
function elapsedtime($seconds) {
if ($seconds > 86400) {
$seconds -= 86400;
return(gmdate("j\d H:i:s", $seconds));
} else
return(gmdate("H:i:s", $seconds));
}
$listenersArray["Total"]["
$listenersArray["Total"]["
$station_name = "Emphatic Radio.com!";
$refresh = "60"; // Page refresh time in seconds. Put 0 for no refresh
$timeout = "1"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline
/* ----------- Server configuration ---------- */
// Note: dont include http://
// Main server: The song title will be taken from this server
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
/* --------------------------
$servers = count($ip);
?>
<?
$i = "1";
while($i<=$servers)
{
$fp = @fsockopen($ip[$i],$port[$
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head>
$info = str_replace('</body></html
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span><p><b>List
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
$i++;
}
$total_listeners = array_sum($listeners) ;
$total_slots = array_sum($max) ;
$availableslots = ($total_slots-$total_liste
print "<div id=\"blu\">\n <div style=\"text-align: center;\">\n <font size=\"4\">\nThere are $total_listeners listeners locked <br> $availableslots available slots remaining
</font>\n </div>\n</div>\n<div>\n <div>\n <p><b>Current song:</b> $song[1]</p>\n </div>\n</div>\n<div>\n";
$i = "1";
while($i<=$servers)
{
print " <div>\n";
if ($max[$i] > 0)
{
$percentage = round(($listeners[$i] / $max[$i] * 100));
$timesby = (300 / $max[$i]);
$barlength = round(($listeners[$i] * "$timesby"));
}
if ($error[$i] = 1)
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"><img src="images/<? if ($percentage == "100") { print "red-"; } ?>bar.gif" width="<? print $barlength ?>" height="12" alt="The server is at <? print $percentage; ?>% capacity"></td>
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
else
{
?>
<br>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25%" align="center"><b>Server <? print $i ?> (<? print $location[$i] ?>)</b> </td>
<td width="75%" colspan="3" bgcolor="#eeeeee"> </
</tr>
<tr>
<td width="25%"> </td>
<td width="25%">0%</td>
<td width="25%" align="center">50%</td>
<td width="25%" align="right">100%</td>
</tr>
</table>
<?
}
$fp = @fsockopen($ip[$i],$port[$
if (!$fp)
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [Connection refused / Server down]</span>";
$error[$i] = "1";
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head>
$info = str_replace('</body></html
$stats = explode(',', $info);
if (empty($stats[1]) )
{
$listeners[$i] = "0";
$msg[$i] = "<span class=\"red\">ERROR [There is no source connected]</span>";
$error[$i] = "1";
}
else
{
if ($stats[1] == "1")
{
$song[$i] = $stats[6];
$listeners[$i] = $stats[0];
$max[$i] = $stats[3];
$bitrate[$i] = $stats[5];
$peak[$i] = $stats[2];
$gi = geoip_open("geostats/GeoIP
for ($count = 0;$count < count($servers); $count++) {
$shoutcast = new ShoutCast();
$shoutcast->name = $location[$i];
$shoutcast->host = $ip[$i];
$shoutcast->port = $port[$i];
$shoutcast->passwd = $password[$i];
$listenersArray["$shoutcas
$listenersArray["$shoutcas
if ($shoutcast->openstats()) {
// We got the XML, gogogo!..
unset($from);
if ($shoutcast->GetStreamStat
$listenersArray["$shoutcas
$listenersArray["$shoutcas
$listenersArray["Total"]["
$listenersArray["Total"]["
$listeners_geo = $shoutcast->GetListeners()
if (is_array($listeners_geo))
for ($is=0;$is<sizeof($listene
$country_id = geoip_country_id_by_name($
$country_name = $GLOBALS['GEOIP_COUNTRY_NA
if (!$country_id) {
$country_id = 0;
$country_name = "Earth(unidentified)";
}
$from["$country_id"]++;
}
} else {
echo "
Noone listens right now..
\n";
}
echo " \n";
} else {
echo "Server is up, but no stream available..
\n";
}
} else {
// Ohhh, damnit..
echo $shoutcast->geterror();
echo "\n \n \n";
}
echo " \n";
$count++;
}
geoip_close($gi);
?>
<br>
<table border=\"1\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\" align="center">
<tr>
<td>Flag</td>
<td>Country</td>
<td>Listeners</td>
</tr>
<tr>
<?php
arsort($from);
reset($from);
while (list($key, $val) = each($from)) {
$country_code = $GLOBALS['GEOIP_COUNTRY_CO
$country_name = $GLOBALS['GEOIP_COUNTRY_NA
if (!$country_code) {
if (!$key && $key != 0) {
$country_code = $key;
} else {
// I don't want to show unidentified hosts in ranking.
// $country_code = "N/A";
continue;
}
}
echo"<td><img src=\"geostats/$country_co
<td> $val</td></tr></table>
\n";
$countrycount++;
if ($countrycount >= $countrylimit) break;
}
$msg[$i] = "<span class=\"red\">Server is up at $bitrate[$i] kbps with $listeners[$i] of $max[$i] listeners</span>
<br>
<br>
<b>Web Hits:</b> ".$shoutcast->GetWebHitsCo
<p><b>Listener Peak:</b> $peak[$i]";
}
else
{
$listeners[$i] = "0";
$msg[$i] = " <span class=\"red\">ERROR [Cannot get info from server]</span>";
$error[$i] = "1";
}
}
}
print " <p><b>Status:</b> $msg[$i]</p>\n </div>\n <div class=\"line\"> </div>\n";
$i++;
}
print "</div>\n";
$time_difference = "0"; // BST: 1 GMT: 0
$time_difference = ($time_difference * 60 * 60);
$time = date("h:ia", time() + $time_difference);
$date = date("jS F, Y", time() + 0);
print "<div>\n <div>\n <p><b>Live SHOUTcast statistics:</b> $date, $time</p>\n </div>\n</div>\n";
?>
<div>
<div>
ASKER
unset($from); fixed the problem.
Thanks for your help!
Thanks for your help!
Glad i could help.
$ip[1] = "xxxx";
$port[1] = "xxxx";
$location[1] = "U.K.";
$password[1] = "xxxx";
$ip[2] = "xxxx";
$port[2] = "xxxx";
$location[2] = "U.K.";
$password[2] = "xxxx";
$ip[3] = "xxxx";
$port[3] = "xxxx";
$location[3] = "U.S.";
$password[3] = "xxxx";
and in the url you gave it deisplays 3 servers.