functions to retrieve the last modified date from files on remote servers. very practical to check if a new version of a file is ready to download on
another server.
01<?php 02 03functionget_raw_header($host,$doc) 04{ 05$httpheader=''; 06$fp=fsockopen($host,80,$errno,$errstr,30); 07if(!$fp) 08{ 09echo$errstr.' ('.$errno.')'; 10}else{ 11fputs($fp,'GET '.$doc.' HTTP/1.0'."\r\n".'Host: '.$host."\r\n\r\n"); 12while(!feof($fp)) 13{ 14$httpresult=fgets($fp,1024); 15$httpheader=$httpheader.$httpresult; 16if(ereg("^\r\n",$httpresult)) 17break; 18} 19fclose($fp); 20} 21return$httpheader; 22} 23 24functionget_header_array($url) 25{ 26$url=ereg_replace('http://','',$url); 27$endHostPos=strpos($url,'/'); 28if(!$endHostPos)$endHostPos=strlen($url); 29$host=substr($url,0,$endHostPos); 30$doc=substr($url,$endHostPos,strlen($url)-$endHostPos); 31if($doc=='')$doc='/'; 32$raw=get_raw_header($host,$doc); 33$tmpArray=explode("\n",$raw); 34for($i=0;$i<sizeof($tmpArray);$i++) 35{ 36@list($name,$value)=explode(':',$tmpArray[$i],2); 37$array[trim($name)]=trim($value); 38} 39return$array; 40} 41 42// use like this to find out when a file on a server was last modified 43 44// should be a static file like a .zip archive for example 45$remote_file='http://fundisom.com/MakeNewFolderNamed.dmg'; 46 47$array=get_header_array($remote_file); 48 49echo' 50<p> 51 '.$remote_file.' was last modified on '.date('j F Y',strtotime($array['Last-Modified'])).' 52</p>'; 53 54?>