I'm trying to retrieve the last modified information of a webpage? I don't even know if php would do it or would javascript be better better for this. I've tried document.lastmodified with java script but that does not help much.

I've noticed that in firefox ->tools->page info gives me the exact date/time of any webpage when was it last modified. But I don't know how to get that info displayed about any website on my webpage.

but how/where do I enter the webpage's address whose date/time of last update i'm looking for?

Got this from the pHp manual:

<?php

// get remote file last modification date (returns unix timestamp)
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;
}
?>
This article has been dead for over six months. Start a new discussion instead.