News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Putting Ajax in this code..

Started by brianjw, February 12, 2008, 05:25:23 PM

Previous topic - Next topic

brianjw

I would like to make it so this thing was updated in realtime so it is ajax. Here is the code I want to make ajax powered:
Code (sc_status.php) Select

<?php
////////////////////////////////////////////////////////////////////////////////
// script name: sc status
// date: 10/13/2005
// author: [email protected]
// cause: checks status of a shoutcast server and display's online or offline status
// version: 0.2b
// platform independant
// file name: sc_status.php
////////////////////////////////////////////////////////////////////////////////
//do not get cute and monkey with anything below, unless you know what u are doing.
include ('./config.php');
// override ini settings for script execution time, we dont need a minute to decide
// if a server is up or not, 10 seconds should be sufficient.
ini_set("max_execution_time", "10");

//check config settings
if($useimage == 'yes' && $usetext == 'yes'){
   echo
'You must choose text display or image display but not both<br>
        please edit your config.php file<br>[ERROR: 1]'
;
   exit();
}
//lets initiate a tcp socket connection to determine whether or not the server
//is actualy up.
$scp = @fsockopen($sc_ip, $sc_port, &$errno, &$errstr, 30);
//let me know where or not its up
   
if(!$scp){
       
$sock_init = 'FALSE';
   }

//show them whether or not the server is actualy up or not
   
if($sock_init == 'FALSE'){
       if(
$useimage == 'yes'){
           echo
'<img src='.$offline_imgurl.'>';
       }else if (
$usetext == 'yes'){
           echo
''.$station_name.' - '.$offline_text.'';
       }
   }
//check 7.html to see if dsp is connected
   
if($sock_init != 'FALSE'){
       
fputs($scp,"GET /7.html HTTP/1.0\r\nUser-Agent: SC Status (Mozilla Compatible)\r\n\r\n");
        while(!
feof($scp)) {
             
$sc7 .= fgets($scp, 1024);
            }
//close it up
@fclose($scp);
//while we got the page open into memory lets bomb n parse baby.
$sc7 = ereg_replace(".*<body>", "", $sc7);
$sc7 = ereg_replace("</body>.*", ",", $sc7);
$sc_contents = explode(",",$sc7);
$dummy = $sc_contents[0];
$dsp_connected = $sc_contents[1];


//check dsp connection and display the status of the shoutcast server in question
//do images first
   
if($sock_init != 'FALSE'){
        if(
$dsp_connected == '1' && $useimage == 'yes'){
         echo
'<img src='.$online_imgurl.'>';
    }else if (
$dsp_connected != '1' && $useimage == 'yes'){
       echo
'<img src='.$offline_imgurl.'>';
    }
}
//do text if set
if($sock_init != 'FALSE'){
   if (
$dsp_connected == '1' && $usetext == 'yes'){
       echo
''.$station_name.' - '.$online_text.'';
    }else if(
$dsp_connected != '1' && $usetext == 'yes'){
        echo
''.$station_name.' - '.$offline_text.'';
    }
}

}
//end 7.html
   
//EOF
?>


Thanks so much!
brianjw

Panzer-

If your not confident at making source edits, you could put it in the global headers and footers. Alternatively into a Tinyportal block

Advertisement: