realisticp
12-11-2009, 06:27 AM
Respected Members,
In php,
How can I get last modified date of a give web page?
I have tried to get last modified from the header but for some pages the server of that webpage doesn't returns last modified date.
How can I do this with php?
rasin
12-11-2009, 07:54 AM
using javascript you will get the last modified time of your own script
<script>
document.write("last modified"+document.lastModified);
</script>
or using php you will get the last modified time of the specified url
found this code in
http://pb11.php.net/manual/fr/function.filemtime.php
<?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;
}
?>
hope this helps you
Rasin
mattle
12-11-2009, 09:51 AM
Do rasin's suggestion if this is a remote file that you don't have write access to. If you can write to the file, check out the stat (http://php.net/manual/en/function.stat.php) function.