Get last modified date of web page

Discussion in 'PHP' started by selva.k, Dec 10, 2009.

  1. #1
    Hai All,

    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 lastmodified date.How can i do this with php ?

    Thanks in advance......
     
    selva.k, Dec 10, 2009 IP
  2. metapix

    metapix Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php
    
    // read the curent file 
    $fp = fopen(__FILE__, "r");
    
    // get file statistics
    $fstat = fstat($fp);
    
    // print the last modification time
    echo $fstat['mtime'];
    ?>
    PHP:
    OR

    <?php
    
    echo date("F d Y H:i:s.", getlastmod());
    
    ?>
    PHP:
    OR

    <?php
    
    echo date ("F d Y H:i:s.", filemtime(__FILE__));
    
    ?>
    PHP:
     
    Last edited: Dec 10, 2009
    metapix, Dec 10, 2009 IP
  3. selva.k

    selva.k Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for replay..

    In need to get lastmodified date for webpage for other websites in internet via http reponse or through other techniques..
     
    selva.k, Dec 10, 2009 IP
  4. markowe

    markowe Well-Known Member

    Messages:
    1,136
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    165
    #4
    I did it something like this:

    $conn = @fopen($httpAddress);
    $meta = stream_get_meta_data ($conn);
    
    Code (markup):
    This returns an array of the metadata, and Last Modified is in a subarray called "wrapper_data" with key 4:

    echo $meta['wrapper_data'][4];
    Code (markup):
    This also contains the words "Last-Modified: ", so you can do:

    $dateForHumans = preg_replace('#Last-Modified: #', '', $meta['wrapper_data'][4]);
    $LastModified = strtotime($dateForHumans);
    Code (markup):
    Not sure if that is what you are looking for but works for me. Check the code, cos I copied it from some script of mine, the variable names might be mixed up or something.
     
    markowe, Dec 10, 2009 IP
  5. mahfuzit

    mahfuzit Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Wow! I was searching these codes.
     
    mahfuzit, Dec 10, 2009 IP