Core Coding®

Get Remote Timestamp

  Get Remote Timestamp
Get the timestamp of a file from a remote web server
function GetRemoteLastModified($uri) {
    
// default
    
$unixtime 0;

    
$fp fopen$uri"r" );
    if (!
$fp) {return;}

    
$MetaData stream_get_meta_data$fp );

    foreach( 
$MetaData['wrapper_data'] as $response) {
        
// case: redirection
        
if( substrstrtolower($response), 010 ) == 'location: ' )
        {
            
$newUri substr$response10 );
            
fclose$fp );
            return 
GetRemoteLastModified$newUri );
        }
        
// case: last-modified
        
elseif( substrstrtolower($response), 015 ) == 'last-modified: ' )
        {
            
$unixtime strtotimesubstr($response15) );
            break;
        }
    }
    
fclose$fp );
    return 
$unixtime;
}

function 
showDayTime($theday$full false) {
  return (!
$theday)?"None":date("m/d/" . (($full)?'Y':'y') . " h:ia"$theday);
}

$stamp GetRemoteLastModified('http://www.iloveinns.com/images/mastlogo.gif');
$stamp showDayTime($stamp);
echo 
$stamp;
echo 
"\n";

Go back to resources
Home Mail GitHub