For Modified date of web page

by jasim1
1 replies
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?
#date #modified #page #web
  • Profile picture of the author Bruce Hearder
    Hi..

    There is an example over on php.net that might do what you want.
    It was posted by :solarijj at gmail dot com

    and coping right from that page the PHP is as follows:

    ==============================================
    // 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;
    }
    =============================================

    I hope this helps

    Bruce
    {{ DiscussionBoard.errors[1528678].message }}

Trending Topics