What are some best practices for automatically displaying the last modified date of a webpage using PHP?

When displaying the last modified date of a webpage automatically using PHP, it is important to ensure that the date is accurate and updates whenever the webpage is modified. One way to achieve this is by using the filemtime() function in PHP to retrieve the last modified timestamp of the webpage file. This timestamp can then be formatted and displayed on the webpage to inform users of when the page was last updated.

<?php
$filename = $_SERVER['SCRIPT_FILENAME'];
if (file_exists($filename)) {
    $lastModified = date("F d Y H:i:s.", filemtime($filename));
    echo "Last modified: " . $lastModified;
} else {
    echo "File not found.";
}
?>