PX : code

ServerPush by Fabian Dennler
Download this code


<?

/*------------------------------------------------------------------------------------

  Server push PHP3 script
  -------------------------------
  A very short routine to perform simple server push animation, 
  with browser detection snippset. Server push work's only with 
  Netscape 4.0 or higher.

  Author: Fabian Dennler, fab@harlequin.ch
  Date:   01.05.2000
  
  Insert the server push script like an image in your html file.
  i.e. <IMG SRC="campush.php3">

------------------------------------------------------------------------------------*/

 // filelocation of the webcam image
 $filename= "cam.jpg";

 // how many time between push    
 // for unbuffered output set to 1.
 $pause = "10"; 

 // how many time to pass to passthru function , don't set this to high for server usage
 $PASSES = 20; 
 






/*------------------------------------------------------------------------------------
for ($j=0;$j<=$PASSES;$j++) {
    $img[count($img)] = $filename;

/*------------------------------------------------------------------------------------



/*------------------------------------------------------------------------------------*/
     /* Plot the Currrent Data Block of the image */
/*------------------------------------------------------------------------------------*/
function plot_cam() {
        global $filename,$img,$pause;
        $k = 0;
        Header("Content-type: multipart/x-mixed-replace;boundary=ThisRandomString");
        while ($img[$k]==$filename) {
            print("\n--ThisRandomString\n\n");
            Header("Content-type: text/plain");
            $cam = fopen($filename,"r"); 
            fpassthru($cam);
             fclose($cam);
            if ($pause) { sleep($pause);} // time between reload, usefull for server usage
            $k++;
            if ($k==count($img)) {
                echo("\n--ThisRandomString--\n");                    
            }
         }    
}


/**************************************************************************************/

     Broser Detection is provided by Leon Atkinson <leon@clearink.com>

/*------------------------------------------------------------------------------------*/
     /* Get the name the browser calls itself and what version */
    $Browser_Name = strtok($HTTP_USER_AGENT, "/");
    $Browser_Version = strtok(" ");
    /* MSIE lies about its name */
    if(ereg("MSIE", $HTTP_USER_AGENT))    {
        $Browser_Name = "MSIE";
        $Browser_Version = strtok("MSIE");
        $Browser_Version = strtok(" ");
        $Browser_Version = strtok(";");
    }
    /* Opera isn't completely honest, either ... */
    /* Modificaton by Chris Mospaw <mospaw@polk-county.com> */
    if(ereg("Opera", $HTTP_USER_AGENT))    {
        $Browser_Name = "Opera";
        $Browser_Version = strtok("Opera");
        $Browser_Version = strtok("/");
        $Browser_Version = strtok(";");
    }
    /* try to figure out what platform, windows or mac */
    $Browser_Platform = "unknown";
    if(ereg("Windows",$HTTP_USER_AGENT) 
        || ereg("WinNT",$HTTP_USER_AGENT) 
        || ereg("Win95",$HTTP_USER_AGENT)) {
            $Browser_Platform = "Windows";
    }
    if(ereg("Mac", $HTTP_USER_AGENT)) {
        $Browser_Platform = "Macintosh";
    }
    if(ereg("X11", $HTTP_USER_AGENT)) { 
        $Browser_Platform =  "Unix"; 
    } 

    if(($Browser_Platform == "Windows")){
        if($Browser_Name == "Mozilla")    {
            if($Browser_Version >= 3.0)    {
            }        
            // SERVER PUSH WORK'S ONLY HERE :)
            if($Browser_Version >= 4.0)    { plot_cam(); }
        }
    }

    elseif($Browser_Platform == "Macintosh") {
        if($Browser_Name == "Mozilla") {
            if($Browser_Version >= 3.0)    {
            }        
            // SERVER PUSH WORK'S ONLY HERE :)
            if($Browser_Version >= 4.0)    {plot_cam();}
        }
    }
    elseif($Browser_Platform ==  "Unix") { 
        if($Browser_Name ==  "Mozilla") { 
            if($Browser_Version >= 3.0) { 
            }         
            // SERVER PUSH WORK'S ONLY HERE :)
            if($Browser_Version >= 4.0) { plot_cam();} 
        } 
    }

exit;    
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.