View Full Version : Help with echo please?

12-06-2008, 03:08 AM
I want this to show a link when the radio is online, I can not get it to work help?


$server = "{IP HERE, Took out for my reasons}"; // IP address to your shoutcast server.
$port = "8010"; // port of your shoutcast server
$online = "../../Images/Stats/On Air/On Air.gif"; // Online Gif image
$offline = "../../Images/Stats/Off Air/Off Air.gif"; // offline gif image

// Start Data Collection
$fp = fsockopen("$server", $port, $errno, $errstr, 30);
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n\r\n");
while (!feof($fp)) {
$content .= fgets($fp,128);
// start data processing
$debut = strpos($content, '<body>') + strlen('<body>');
$fin = strpos($content, '</body>', $debut);
$string = substr($content, $debut, $fin - $debut);
$stats = explode(',', $string);

// Start Image generation
// Dedug Status echo "$stats[1]";
if ($stats[1] == "0" || !$stats) {
header("Location: $offline");

if ($stats[1] == "1") {
header("Location: $online");
echo '<p><a href="Http://www.google.com"> Listen Live</p></a>';


12-06-2008, 03:51 AM
echo '<p><a href="Http://www.google.com"> Listen Live</p></a>';

try changing it to this...

echo '<p><a href="Http://www.google.com"> Listen Live</a></p>';

i dont know if that will do what you want...

12-06-2008, 03:59 AM
Its not showing up right,
Its 'on' right now, no link is showing though

12-06-2008, 04:33 AM
All you are doing is sending a .gif image to the browser. As such, it is not capable of being a link.

Please describe in better detail what you are trying to accomplish.

12-06-2008, 08:26 PM
I want it so when it shows its online, underneath the On Air image to show a link in red that users will be able to click to listen to the radio... a pop up window (_new)

12-06-2008, 09:01 PM
Then you are going to have to output your image and the link as part of an html page, not just sending the .gif image to the browser.

12-06-2008, 09:02 PM
How would I go about doing this?

12-06-2008, 10:50 PM
Well, I don't know what the rest of your page looks like or where you would want it, so in general -

The problem is your use of header(). That is what is causing the .gif to be sent to the browser instead of the html page.

So, something along the lines of:

if ($stats[1] == "0" || !$stats) {
echo $offline;

if ($stats[1] == "1") {
echo $online;
echo '<p><a href="http://example.com" target="_blank"> Listen Live</p></a>';


1. You'll have to position this in the page where you'd like it displayed.
2. The use of target="_blank" will accomplish the pop-up window, but it makes use of deprecated, invalid code. You would have to look into a JS solution otherwise.
3. You'll need to correct the href= attribute to point to the correct page.