<?

# cam_status.php - function to check if a webcam is online
# Copyright 2001 Ben Livingston <ben at oblivion dot net>
# Released under the GNU General Public License Version 2
# Viewable online at http://www.gnu.org/copyleft/gpl.html

function cam_status($server,$file) {
  
$fp fsockopen ($server80$errno$errstr30)        // Open connection to server
    
or die("NO DATA");
  
fputs ($fp"HEAD $file HTTP/1.0\r\n\r\n");                // Send HEAD request for file
  
while (!feof($fp)) {
    
$line fgets($fp,128);
    if (
ereg('^Last-Modified: ',$line)) {                    // Check for 'Last-Modified: ' header
      
$line eregi_replace('Last-Modified: ','',$line);
      if ((
time() - strtotime($line)) < 600)                // If under 10 minutes, ONLINE
        
$result "ONLINE";
      else 
$result "OFFLINE";                                // Else OFFLINE
    
}
  }
  
fclose ($fp);
  if (!
$result$result "NOT SURE";                        // If no result, NOT SURE
  
return("$result");
}
?>