1. Computing

Automatically display when a file was last modified on your website


If your website contains time sensitive information (or even if it doesn't) you may want to display the last time a file was modified on your website. This gives users an accurate idea of how up to date the information on a page is. You can automatically draw this information from the file itself using the filemtime () PHP function.

The filemtime () PHP function retrieves the Unix timestamp from the file itself of when the file was last being written. This can show us when a file was last modified.

Example Code:

$last_mod = filemtime("filename.php");
print("Last Edited on ");
print(date("m/j/y h:i", $last_mod));

Be sure to replace "filename.php" with the actual name of the file you are checking on. This could be the file where you are printing the last modified date, or it could be an outside file you are checking on.

©2014 About.com. All rights reserved.