Friday, August 03, 2007

"Last Modified" in PHP

This is nothing exciting, but I just wanted to share :-)

If you want to put in your php web page the well known "Last Modified: " you can simply put this code:

<?php
echo "<b>Last modified:</b> " .
date( "F d, Y. H:i:s a", filemtime("YOUR FILENAME") );
?>

where, of course, you must substitute YOUR FILENAME with the filename of your web page.

That's it!

4 comments:

Anonymous said...

Wow, Php, I am now learning how to program...

Xavier said...

You can simply use the constant __FILE__ to refer to the current file.

This is also useful to determine the path your PHP app is running from... you can simply use $app_root = dirname(__FILE__);

betto said...

Yes you're right!

It's that I'm using this code in a php script where I include an html which contains the actual page: I modify the html page and not the php file, thus I don't use __FILE__ but the name of the .html.

By the way, I liked your blog, Xavier! :-)

Anonymous said...

PHP is not a programming language, it is a server script