PHP Get The Time Of The Last Modification Of The Current Page


Share:
 | Published By: Admin | Published On: Dec 17, 2021 | Category: PHP


Hi Dev,

This example is php get the time of the last modification of the current page

Sometimes, we need to get the last modification time of the current page in PHP for different uses. Since we are using PHP, we can easily get the last modification time of the current page by using getlastmod() PHP function.

This is a Using getlastmod() Function: The getlastmod() function is used to get the last modification time of the current page. This function is easy and powerful.

So let's start following example.

Syntax:

$last_modification="Last modified on: " . date ("F d Y H:i:s.", getlastmod());
Example : 1

The following is the complete code to get and show the last modification time of the current page.

<?php

    // To Get the last modification time.
    $last_modification="Last modified: " . date ("F d Y H:i:s.", getlastmod());  
  
    // To Show the last modification time.
    echo $last_modification;

?>
Output:

Last modified: December 17 2021 10:46:34.
Example : 2

This Using filemtime() Function: The filemtime() function in PHP is an inbuilt function that is used to return the last time of a specified file when its content was modified.

<?php

    // checking last time the contents 
    // of a file were changed 
    echo filemtime("index.html.txt"); 
    
    // checking last time the contents of 
    // a file were changed and formatting 
    // the output of the date  
    echo "Last modified: ".date("F d Y H:i:s.",filemtime("index.html")); 

?>
Output:

Last modified: December 17 2021 10:46:34.

I hope it can help you....

Share: