HotelUser
29-11-2008, 04:23 AM
I wrote this stats script for my own use, and to use within other scripts I'm writing. It's very easy to configure. Just change the host, port, and adminpass as instructed. I hope it can be of use to some of you!
Paste this into a file called stats.php, you only need to change the password, and connection information and it will work:
<?php
/*-------------------------------------------------------------------------------------------------------------------------
SHOUTcast stats script created by Macmee (HotelUser on HxF)
Please change the settings below:
-------------------------------------------------------------------------------------------------------------------------*/
$host = "111.111.1.11"; # the IP address of your server
$port = "8000"; #the port your server's on
$adminpass = "changeme"; #the ADMINISTRATOR password
//end of configuration. You shouldn't change anything beyond this point
$fp = fsockopen ($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /admin.cgi?pass={$adminpass}&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
while (!feof($fp)) {
$content .= fgets ($fp,128);
}
fclose ($fp);
}
$status = explode('<STREAMSTATUS>',$content);
$status = explode('</STREAMSTATUS>',$status[1]);
if($status[0] == 0)
{
die('<center>Our radio is currently <font color=red><b>offline</b>!</font></center>');
}
$listeners = explode('<CURRENTLISTENERS>',$content);
$listeners = explode('</CURRENTLISTENERS>',$listeners[1]);
$maxlisteners = explode('<MAXLISTENERS>',$content);
$maxlisteners = explode('</MAXLISTENERS>',$maxlisteners[1]);
$servertitle = explode('<SERVERTITLE>',$content);
$servertitle = explode('</SERVERTITLE>',$servertitle[1]);
$song = explode('<TITLE>',$content);
for($i=1; $i<=10; $i++)
{
$song[$i] = explode('</TITLE>',$song[$i]);
$song[$i] = $song[$i][0];
}
echo '<center>';
echo "<b>Listeners:</b> {$listeners[0]} / {$maxlisteners[0]}<br><br>";
echo "<b>Current DJ:</b> {$servertitle[0]}<br><br>";
echo "<b>Current Song:</b> {$song[1]}<br><br>";
echo "<b>Recent Songs:</b><br>";
foreach($song as $id => $value)
{
if($id != 0 && $id != 1)
{
$display = $id - 1;
echo "<b>{$display}</b>. {$value}<br>";
}
}
echo '</center>';
?>
Thread closed by Matts (Forum Super Moderator): Due to bump.
Paste this into a file called stats.php, you only need to change the password, and connection information and it will work:
<?php
/*-------------------------------------------------------------------------------------------------------------------------
SHOUTcast stats script created by Macmee (HotelUser on HxF)
Please change the settings below:
-------------------------------------------------------------------------------------------------------------------------*/
$host = "111.111.1.11"; # the IP address of your server
$port = "8000"; #the port your server's on
$adminpass = "changeme"; #the ADMINISTRATOR password
//end of configuration. You shouldn't change anything beyond this point
$fp = fsockopen ($host, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "GET /admin.cgi?pass={$adminpass}&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");
while (!feof($fp)) {
$content .= fgets ($fp,128);
}
fclose ($fp);
}
$status = explode('<STREAMSTATUS>',$content);
$status = explode('</STREAMSTATUS>',$status[1]);
if($status[0] == 0)
{
die('<center>Our radio is currently <font color=red><b>offline</b>!</font></center>');
}
$listeners = explode('<CURRENTLISTENERS>',$content);
$listeners = explode('</CURRENTLISTENERS>',$listeners[1]);
$maxlisteners = explode('<MAXLISTENERS>',$content);
$maxlisteners = explode('</MAXLISTENERS>',$maxlisteners[1]);
$servertitle = explode('<SERVERTITLE>',$content);
$servertitle = explode('</SERVERTITLE>',$servertitle[1]);
$song = explode('<TITLE>',$content);
for($i=1; $i<=10; $i++)
{
$song[$i] = explode('</TITLE>',$song[$i]);
$song[$i] = $song[$i][0];
}
echo '<center>';
echo "<b>Listeners:</b> {$listeners[0]} / {$maxlisteners[0]}<br><br>";
echo "<b>Current DJ:</b> {$servertitle[0]}<br><br>";
echo "<b>Current Song:</b> {$song[1]}<br><br>";
echo "<b>Recent Songs:</b><br>";
foreach($song as $id => $value)
{
if($id != 0 && $id != 1)
{
$display = $id - 1;
echo "<b>{$display}</b>. {$value}<br>";
}
}
echo '</center>';
?>
Thread closed by Matts (Forum Super Moderator): Due to bump.