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.

Member Avatar for diafol

Something like:

date ("F jS, Y \a\t H:i:s", getlastmod());

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

Member Avatar for diafol

Sorry mate, I misunderstood, I thought you wanted to display to last mod of YOUR OWN page. Doh!

Member Avatar for diafol

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;
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.