Core Coding®

Get Remote Timestamp

  Get Remote Timestamp
Get the timestamp of a file from a remote web server
<?php
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( substr( strtolower($response), 0, 10 ) == 'location: ' )
{
$newUri = substr( $response, 10 );
fclose( $fp );
return
GetRemoteLastModified( $newUri );
}
// case: last-modified
elseif( substr( strtolower($response), 0, 15 ) == 'last-modified: ' )
{
$unixtime = strtotime( substr($response, 15) );
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