Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » php » Last Modified Info

Last Modified Info

This tutorial will show you how to display the date/time that the file was last modified.

Here you go, I commented each line, if you have a question don't hesitate to ask.

<?php

// The file to that will read.
$file = 'thefile.php';

// The variable that holds the function to display the date modified info.
$last_time_modified = filemtime($file);

// Format that time and date into a human readable format
$last_mod =  "Page last edited " . date("m/j/y h:i", $last_time_modified);

// print the new formatted string and display the last modified info. 
//You could also pass the "$last_mod" variable to another piece of your script
print $last_mod;

?>


That is the end of the tutorial. I hope you have an understanding of how "filemtime" works.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Last Modified Info

 Mark  Fri Mar 13, 2009 4:46 am  
Thanks for your tutorial above. I found it very useful.

I made a modification so that you don't need to specify a filename:

// $n for a newline
$n = "
";
$path = $_SERVER['PHP_SELF'];
$file = basename($path);
$last_time_modified = filemtime($file);

// use the format you would like the date outputted as, i.e. jS M y
$last_mod = "Last updated: " . date("jS M y - H:i:s T", $last_time_modified) . $n;

print $last_mod;
?>

Use the $_SERVER[''] if Global variables are not enabled on the server.
 Mark  Thu Apr 2, 2009 2:04 pm  
N.B. My earlier comment with php code should have included the following:

1. Starting php tag 2. The new line variable $n =" < br >"; (without the spaces!)
Add a comment
The ability to add new comments has been disabled in this archived version.

Loading
Main | Tutorials | Articles