PDA

View Full Version : SHOUTcast Stats script I wrote



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.

lezerdragon1
09-08-2012, 01:17 PM
Can u help me because this says the stats at my page:

Warning: fsockopen() [function.fsockopen]: unable to connect to (privateIP sorry) (Connection timed out) in /home/u652848935/public_html/stats.php on line 12
Connection timed out (110)
Our radio is currently offline!

(PrivateIP i deleted IP for safety)

Yonder
15-08-2012, 05:52 PM
lezerdragon1; More than likely your host is blocking the port happens a lot on shared servers.


Ooops i just realized this thread was from 2008 -.- sorry mods.

-Tyquan
06-11-2012, 05:38 PM
Can u help me because this says the stats at my page:

Warning: fsockopen() [function.fsockopen]: unable to connect to (privateIP sorry) (Connection timed out) in /home/u652848935/public_html/stats.php on line 12
Connection timed out (110)
Our radio is currently offline!

(PrivateIP i deleted IP for safety)
having the same problem ;p

SORRY This thread is from 08 My bad ;p

Want to hide these adverts? Register an account for free!