Old 7th February 2005, 17:52   #1
bulldawg11
Junior Member
 
Join Date: Feb 2005
Posts: 7
php script on-air off-air

hello, i'd like to display the status of a radio...So i'm looking for the easier way to do that. Itried this script

<?

$check1 = fsockopen("ip", "8000");

if ($check1) {
echo ("<image border='0' src='images/on.GIF'>");
$close = fclose($check1);
}
else
echo ("<image border='0' src='images/off.GIF'>");

?>

I have no errors, but it doesnt work... It always shows the off.gif picture, even if i'm broadcasting. So if someone can help me it will be cool.
bulldawg11 is offline   Reply With Quote
Old 8th February 2005, 08:04   #2
Cygnus46n2
Junior Member
 
Join Date: Feb 2005
Posts: 3
This should be what your looking for...


Heres the function...
function check_sc($host, $port) {
@$sock = fsockopen($host, $port, &$num, &$error, 2);
if ($sock) {
if (getservbyport($port,"tcp")!=null) {
$serv = getservbyport($port,"tcp");
} else {
$serv = "Unknown";
}
return "<img border='0' src='images/online.gif' alt='Server Up'>";
fclose($sock);
unset($sock);
}else{
return "<img border='0' src='images/offline.gif' alt='Server Down'>";
unset($sock);
}
}

Then simply call

check_sc('123.123.123.123', '8000');
Cygnus46n2 is offline   Reply With Quote
Old 8th February 2005, 12:27   #3
bulldawg11
Junior Member
 
Join Date: Feb 2005
Posts: 7
I tried your script, and the page is empty...
bulldawg11 is offline   Reply With Quote
Old 8th February 2005, 12:56   #4
bulldawg11
Junior Member
 
Join Date: Feb 2005
Posts: 7
i did an echo "offline" or echo "online" instead of returning an image, and now it displays always offline...Thks for your help
bulldawg11 is offline   Reply With Quote
Old 8th February 2005, 23:11   #5
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
Contrary to what you get, if the DNAS is running both codes should always display the online image because that's what they check, if there's a service on that port. But none of those two codes will check if there's a stream or not. The easier way to get the stream status is parsing the quick stats, [http://host:Port/7.html]

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 9th February 2005, 07:30   #6
Cygnus46n2
Junior Member
 
Join Date: Feb 2005
Posts: 3
that script works fine, just how your using it..

use this...
$sc_status = check_sc('ip', 'port');
echo $sc_status;

just tested it, works just fine, as its returning a result, not just echoing itself out....

only thing is yes it checks just to see if something responds to that port, this doesnt check if someone is actualy streaming music or anything, but it wouldnt be to hard to make something that would check the /7.html and display accordingly..
Cygnus46n2 is offline   Reply With Quote
Old 9th February 2005, 07:47   #7
Cygnus46n2
Junior Member
 
Join Date: Feb 2005
Posts: 3
Also just modified it a bit more... this script will check the 7.html and grab the second variable and if its 0, server is down, if its 1, then there is a source streaming...

// This is the function....
function sc_status($server, $port, $file) {
$cont = "";
$ip = gethostbyname($server);
$fp = fsockopen($ip, $port);
if (!$fp)
{
return "Unknown";
}
else
{
$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp, $com);
while (!feof($fp))
{
$cont .= fread($fp, 500);
}
fclose($fp);
$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
//return $cont;
}
$parts = explode(',', $cont);
$status = $parts['1'];
if ($status == '0') {
return "<img src='image.png' alt='Server is DOWN'>";
} else {
return "<img src='image.png' alt='Server is UP'>";
}

}

// This is what you would call...
echo sc_status('ip_address', 'server_port', '/7.html');

tested works great.
Cygnus46n2 is offline   Reply With Quote
Old 10th February 2005, 00:41   #8
bulldawg11
Junior Member
 
Join Date: Feb 2005
Posts: 7
thks a lot.
bulldawg11 is offline   Reply With Quote
Old 14th February 2005, 08:18   #9
couch-potato
Senior Member
 
couch-potato's Avatar
 
Join Date: Feb 2002
Location: mother earth
Posts: 100
hello

I'm using a similar script. but now i would like to be informed by mail , in case the source dropped !
how would a script like this looks like ?

Regards
Tom

##.:: www.lounge-radio.com ::.##
couch-potato is offline   Reply With Quote
Old 27th February 2005, 06:34   #10
russellscott
Junior Member
 
Join Date: Feb 2005
Posts: 8
this is what i'm using

<?php
if(!isset($ip)) $ip = "insert.your.ip.here";
if(!isset($port)) $port = 8000;
$timeout = 4;

if (isset($ip) && isset($port)) {
$fp = @fsockopen($ip,$port,$errno,$errstr,$timeout);
if ($fp) echo " <b><a href=\"http://$ip:8000/listen.pls\" target=\"_blank\">online</a></b>";
else echo "offline";
}
else echo "You are missing the IP Address and/or Port";
?>
russellscott is offline   Reply With Quote
Old 2nd March 2005, 04:43   #11
captainash
Junior Member
 
Join Date: Mar 2005
Posts: 2
I'm a nooblet with anything but the basics of HTML.. Can someone please help me?

captainash_1 AT HOT MAIL DOT COM
captainash is offline   Reply With Quote
Old 12th March 2005, 21:45   #12
djjonni
Junior Member
 
Join Date: Feb 2005
Location: Belfast UK
Posts: 1
Send a message via ICQ to djjonni Send a message via AIM to djjonni
Quote:
Originally posted by Cygnus46n2
Also just modified it a bit more... this script will check the 7.html and grab the second variable and if its 0, server is down, if its 1, then there is a source streaming...

// This is the function....
function sc_status($server, $port, $file) {
$cont = "";
$ip = gethostbyname($server);
$fp = fsockopen($ip, $port);
if (!$fp)
{
return "Unknown";
}
else
{
$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp, $com);
while (!feof($fp))
{
$cont .= fread($fp, 500);
}
fclose($fp);
$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
//return $cont;
}
$parts = explode(',', $cont);
$status = $parts['1'];
if ($status == '0') {
return "<img src='image.png' alt='Server is DOWN'>";
} else {
return "<img src='image.png' alt='Server is UP'>";
}

}

// This is what you would call...
echo sc_status('ip_address', 'server_port', '/7.html');

tested works great.
add <?php to the start and ?> to the end so ya get .............



<?php
// This is the function....
function sc_status($server, $port, $file) {
$cont = "";
$ip = gethostbyname($server);
$fp = fsockopen($ip, $port);
if (!$fp)
{
return "Unknown";
}
else
{
$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp, $com);
while (!feof($fp))
{
$cont .= fread($fp, 500);
}
fclose($fp);
$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
//return $cont;
}
$parts = explode(',', $cont);
$status = $parts['1'];
if ($status == '0') {
return "<img src='http://img.photobucket.com/albums/v209/djjonni/off.png' alt='Server is DOWN'>";
} else {
return "<img src='http://img.photobucket.com/albums/v209/djjonni/air.gif' alt='Server is UP'>";
}

}

// This is what you would call...
echo sc_status('213.48.102.230', '9234', '/7.html');
?>
djjonni is offline   Reply With Quote
Old 25th March 2005, 17:29   #13
Allenrocks
Junior Member
 
Join Date: Mar 2005
Posts: 22
can someone do it for me?
email me at

allen.steam@gmail.com

and ill give you online and offline
Allenrocks is offline   Reply With Quote
Old 25th March 2005, 17:49   #14
Baskido
Senior Member
 
Baskido's Avatar
 
Join Date: Apr 2004
Location: ^ in a tree
Posts: 291
Allen, almost nobody from here gives email support. keep it on these forums

I'm Back!
Tune In!
Baskido is offline   Reply With Quote
Old 3rd April 2005, 23:50   #15
tuckerm
Forum Emo
 
tuckerm's Avatar
 
Join Date: Mar 2005
Posts: 8,365
put one of the scripts on there..do u have any idea why there is still text:

http://www.freewebs.com/mystuffradio

(on bottom)
tuckerm is offline   Reply With Quote
Old 4th April 2005, 01:42   #16
101
Major Dude
 
101's Avatar
 
Join Date: Jul 2004
Location: Argentina
Posts: 828
Send a message via ICQ to 101
freewebs.com doesn't support PHP, if you still want to use their service, you can run the script on another host and load it on an iFrame from freewebs.

Words are very unnecessary, they can only do harm, so enjoy the silence - Depeche Mode
Firemonger Project: Help spread Firefox
101 is offline   Reply With Quote
Old 4th April 2005, 01:45   #17
tuckerm
Forum Emo
 
tuckerm's Avatar
 
Join Date: Mar 2005
Posts: 8,365
anyone here that has an html script??

Last edited by tuckerm; 4th April 2005 at 02:15.
tuckerm is offline   Reply With Quote
Old 4th April 2005, 07:35   #18
Nick@ss
Moderator
 
Nick@ss's Avatar
 
Join Date: Nov 2004
Location: Streamsolutions Headquarters
Posts: 11,953
havent seen one it needs to be php script
Nick@ss is offline   Reply With Quote
Old 6th April 2005, 16:29   #19
eimeo
Junior Member
 
Join Date: Mar 2005
Location: Florida
Posts: 9
Quote:
Originally posted by djjonni
add <?php to the start and ?> to the end so ya get .............



<?php
// This is the function....
function sc_status($server, $port, $file) {
$cont = "";
$ip = gethostbyname($server);
$fp = fsockopen($ip, $port);
if (!$fp)
{
return "Unknown";
}
else
{
$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp, $com);
while (!feof($fp))
{
$cont .= fread($fp, 500);
}
fclose($fp);
$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
//return $cont;
}
$parts = explode(',', $cont);
$status = $parts['1'];
if ($status == '0') {
return "<img src='http://img.photobucket.com/albums/v209/djjonni/off.png' alt='Server is DOWN'>";
} else {
return "<img src='http://img.photobucket.com/albums/v209/djjonni/air.gif' alt='Server is UP'>";
}

}

// This is what you would call...
echo sc_status('213.48.102.230', '9234', '/7.html');
?>
This script is working. The only problem for me is that the Soutcast DNAS server has to be on for this script to work otherwise it takes forever to load and just stays blank

Is there a php script that would also include the fact that the server is offline if the DNAS server is "killed" ?

Last edited by eimeo; 6th April 2005 at 17:38.
eimeo is offline   Reply With Quote
Old 7th April 2005, 03:50   #20
Tom
Moderator
 
Join Date: Apr 2000
Posts: 4,491
You should be able to do it with a little tweking of the posted script. I have not tested this but something along these lines:
PHP Code:
<?php
// This is the function....
function sc_status($server$port$file) {
$cont "";
$ip gethostbyname($server);
// 3 is the timeout in seconds
$fp fsockopen($ip$port$errno$errstr3);
if (!
$fp)
{
return 
"Unknown";
}
else
{
$com "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp$com);
while (!
feof($fp))
{
$cont .= fread($fp500);
}
fclose($fp);
$cont substr($contstrpos($cont"\r\n\r\n") + 4);
//return $cont;
}
$parts explode(','$cont);
$status $parts['1'];
if (
$status == '0') {
return 
"<img src='http://img.photobucket.com/albums/v209/djjonni/off.png' alt='Server is DOWN'>";
} else {
return 
"<img src='http://img.photobucket.com/albums/v209/djjonni/air.gif' alt='Server is UP'>";
}

}

// This is what you would call...
echo sc_status('213.48.102.230''9234''/7.html');
?>
Tom

Tom is offline   Reply With Quote
Old 7th April 2005, 18:29   #21
eimeo
Junior Member
 
Join Date: Mar 2005
Location: Florida
Posts: 9
yeah I was working on it yesterday and I think I got it, but I did not I have time to test it fully yet.
Thanks !
eimeo is offline   Reply With Quote
Old 17th April 2005, 03:46   #22
Tzedek
Junior Member
 
Join Date: Apr 2005
Posts: 15
Send a message via AIM to Tzedek
what needs to be edited with that script?
Tzedek is offline   Reply With Quote
Old 17th April 2005, 05:19   #23
Tzedek
Junior Member
 
Join Date: Apr 2005
Posts: 15
Send a message via AIM to Tzedek
if you are using the radio tool box a simple

<?php

include("includes.php")
echo $server[0]['status'];

?>


Is all you need. PLace that right on your page.
Tzedek is offline   Reply With Quote
Old 14th June 2005, 13:41   #24
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
how do i insert that php into my page? do i have to change the page extension to php instead of html? when i insert it into an html page it just comes up blank.
monkanddave is offline   Reply With Quote
Old 14th June 2005, 14:05   #25
tuckerm
Forum Emo
 
tuckerm's Avatar
 
Join Date: Mar 2005
Posts: 8,365
then your host probably doesnt support php..try another host and use an Iframe to load it onto your homepage
tuckerm is offline   Reply With Quote
Old 14th June 2005, 14:46   #26
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
actually, my host does support php. i use GoDaddy and have a paid PHP hosting service.
monkanddave is offline   Reply With Quote
Old 14th June 2005, 15:33   #27
theodor
Junior Member
 
Join Date: Jan 2005
Location: Sweden
Posts: 28
Hi! I'm sorry i ask but where should the server and port stand?
theodor is offline   Reply With Quote
Old 14th June 2005, 16:52   #28
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
I'm getting this error:

Warning: fsockopen(): unable to connect to 66.57.192.121:8000 in /home/content/m/o/n/monkanddave/html/index.php on line 37
Unknown

It's also taking like 3 minutes to load the page.

Can someone check it out?

http://www.monkanddave.com/index.php
monkanddave is offline   Reply With Quote
Old 14th June 2005, 16:57   #29
tuckerm
Forum Emo
 
tuckerm's Avatar
 
Join Date: Mar 2005
Posts: 8,365
um..why do i have to download your page to get in?
and wheres your script
tuckerm is offline   Reply With Quote
Old 14th June 2005, 17:08   #30
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
i don't have to download the page, i just clicked the link myself and it went to the page, it just took forever.
monkanddave is offline   Reply With Quote
Old 14th June 2005, 17:29   #31
tuckerm
Forum Emo
 
tuckerm's Avatar
 
Join Date: Mar 2005
Posts: 8,365
when you press enter i have to download the page in FF and then open it threw that away..any way give me a dirrect link to the script i can see it any where
tuckerm is offline   Reply With Quote
Old 28th June 2005, 23:12   #32
jacare banguela
Junior Member
 
Join Date: Jun 2005
Posts: 3
im using this code and its working perfectly.
With no black pages and no php errors.

PHP Code:
<?php
$check 
= @fsockopen ("123.123.123.123","8123",$errno$errstr,1); // change 123.123.123.123 to your shoucast ip and 8123 to the port
if($check) {
header('content-type: image/gif');
readfile('on.gif'); // change this to an image you want when shoutcast is on
} else {
header('content-type: image/gif');
readfile('off.gif'); // change this to an image you want when shoutcast is off

}
?>
PS: I think this only completely work with people who have the server on your pc. Sorry my english...
jacare banguela is offline   Reply With Quote
Old 28th June 2005, 23:33   #33
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
I'm getting some REALLY wacky errors with that one. Check out my site: http://www.monkanddave.com
monkanddave is offline   Reply With Quote
Old 29th June 2005, 00:02   #34
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
The exact error I'm getting is:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/o/n/monkanddave/html/index.php:17) in /home/content/m/o/n/monkanddave/html/index.php on line 30
monkanddave is offline   Reply With Quote
Old 29th June 2005, 01:35   #35
jacare banguela
Junior Member
 
Join Date: Jun 2005
Posts: 3
I didnt see the error u are getting on your page.

And im sure this script is working perfectly. Iv tested it in many hosts, the only i got error wah opticalhost.

Try to test the script in other host.

See the script working in my page: click here
jacare banguela is offline   Reply With Quote
Old 29th June 2005, 01:44   #36
monkanddave
Junior Member
 
Join Date: Jun 2005
Posts: 11
i got it to work, but I had to leave off any other html. I can't just insert the php script whereever I want. It has to be the very first thing on the page.

I think I'll be able to get it to work, but I do have one final question: how can I make it so that when my server is on air, the user can click the "on-air" graphic and listen to the show? I just need to know how to link the on-air image to http://i.p.address:8000/listen.pls.

I think I'm going to have to save the script as it's own php file, then somehow place that file on my page. I think an iframe will do the trick, but when I try that, I get scrollbars and a white background. I'm just not familiar enough with iframes to know how to set all the attributes. I'll keep looking.

Does this sound right to anyone?
monkanddave is offline   Reply With Quote
Old 29th June 2005, 05:34   #37
internetbrother
Junior Member
 
Join Date: May 2005
Location: South Korea
Posts: 38
Quote:
Originally posted by jacare banguela
I didnt see the error u are getting on your page.

And im sure this script is working perfectly. Iv tested it in many hosts, the only i got error wah opticalhost.

Try to test the script in other host.

See the script working in my page: click here
Man I want the same thing and the following script

<?php
$check = @fsockopen ("bla bla IP","8182",$errno, $errstr,1); // change 123.123.123.123 to your shoucast ip and 8123 to the port
if($check) {
header('content-type: image/gif');
readfile('on.gif'); // change this to an image you want when shoutcast is on
} else {
header('content-type: image/gif');
readfile('off.gif'); // change this to an image you want when shoutcast is off

}
?>

works but it makes a problem because it needs to be first thing in the page
internetbrother is offline   Reply With Quote
Old 29th June 2005, 10:25   #38
Gorbachov
Junior Member
 
Join Date: Apr 2005
Posts: 12
Send a message via ICQ to Gorbachov
Why don't you use the XML that export the Shoutcast?!
I make some very little tweaks to the script posteted some/w up. And now is the server is down it says it is Down not /Unknown/

PHP Code:
<?php 
// This is the function.... 
function sc_status($server$port$file) { 
$cont ""
$ip gethostbyname($server); 
// 3 is the timeout in seconds 
$fp fsockopen($ip$port$errno$errstr3); 
if (!
$fp

return 
"<img src='http://img.photobucket.com/albums/v209/djjonni/off.png' alt='Server is DOWN'>"

else 

$com "GET $file HTTP/1.1\r\nAccept: */*\r\nAccept-Language: de-ch\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n"
fputs($fp$com); 
while (!
feof($fp)) 

$cont .= fread($fp500); 

fclose($fp); 
$cont substr($contstrpos($cont"\r\n\r\n") + 4); 
//return $cont; 

$parts explode(','$cont); 
$status $parts['1']; 
if (
$status == '0') { 
return 
"<img src='http://img.photobucket.com/albums/v209/djjonni/off.png' alt='Server is DOWN'>"
} else { 
return 
"<img src='http://img.photobucket.com/albums/v209/djjonni/air.gif' alt='Server is UP'>"




// This is what you would call... 
echo sc_status('213.48.102.230''9234''/7.html'); 
?>
Gorbachov is offline   Reply With Quote
Old 29th June 2005, 18:27   #39
jacare banguela
Junior Member
 
Join Date: Jun 2005
Posts: 3
internetbrother and monkanddave
put the script only on a page and save it in PHP(ex: status.php)
Then make an iframe on the page u want to display the radio status.

See an example of an iframe without scrollbars, margin and bords:

<iframe height="25" width="100" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" src="http://blabla.bla/status.php"></iframe>
jacare banguela is offline   Reply With Quote
Old 30th June 2005, 10:43   #40
internetbrother
Junior Member
 
Join Date: May 2005
Location: South Korea
Posts: 38
Quote:
Originally posted by jacare banguela
internetbrother and monkanddave
put the script only on a page and save it in PHP(ex: status.php)
Then make an iframe on the page u want to display the radio status.

See an example of an iframe without scrollbars, margin and bords:

<iframe height="25" width="100" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" src="http://blabla.bla/status.php"></iframe>
Thanks, Very good and it works fine, but I was thinking is it possible to make the image a link. when the radio is on the image can be a link and people click on it and when the radio is off the image is not a link

I think this way will be very cool
internetbrother is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump