it's nice to have your website say "last modified $date" with $date being the last time the page was, modified. this can be done in many ways, here are a few ways in perl, javascript and of course, PHP.
perl isn't bad but imho, the php way is much easier to understand. javascript is just plain nasty and would only be useful if you don't have access to a scripting language such as perl or php. if you don't know what 'a PHP' is then check out some easy-to-follow tutorials.
some questions, contact me with opinions.added timezone support to the tutorial. use this list of timezones to determine your proper last modified date. the examples demonstrate different timezones. I'm from Washington State so I use America/Los_Angeles for my zone.
i find the best way to learn is through examples. the code in the gray boxes is the exact code used while the bottom tan shows what the given php code outputs to the browser. the outputed date is, of course, the date the file was last modified.
| this is your typical last modified function. copy and use freely. |
|
<?php putenv("TZ=America/Los_Angeles"); echo "Last modified: " . date( "F d Y.", getlastmod() ); ?> |
putenv("PHP_TZ=America/Los_Angeles"); echo "Last modified: " . date( "F d Y.", getlastmod() ); ?> |
| html is okay to use. also, am using the |
|
<?php putenv("TZ=America/Los_Angeles"); echo "<b>Any text:</b>" . date( "F d, Y. H:i:s a", getlastmod() ); ?> |
putenv("PHP_TZ=America/Los_Angeles"); echo "Any text: " . date( "F d, Y. H:i:s a", getlastmod() ); ?> |
| you don't have to add text but displaying the date alone is acceptable. also, not setting the timezone just means your servers settings will be used. |
|
<?php echo date( "F d Y h:i:s", getlastmod() ); ?> |
putenv("PHP_TZ=America/Los_Angeles"); echo date( "F d Y h:i:s", getlastmod() ); ?> |
| this basically shows that you can add the variables in any way you choose, and even spell words! |
<?php echo "Foo: " . date( "Family", getlastmod() ); ?> |
echo "Foo: " . date( "Family", getlastmod() ); ?> |
make sense? it's fairly flexible. i don't suggest using the last one as it makes little sense but shows a point, although you are free to use it ;)
i have a little include file which i call: lastmodified.inc. i include this wherever I want to include the last modification date. so, here are the two parts. first, create a include file with your desired look. again, have a look at:
of course you can delete the commented variable list. i find it's helpful to have during initial setup, especially when using a text editor. it's nice having it as an include somewhere though as changing the look and feel of the "Last Modified" date does happen, really it does.
You should notice the use of the getlastmod function, this checks the current file. If you want to check the last modification date of another file then replace it with a variable that calls on the filemtime and use it as such : $myfile = filemtime('/path/to/file/file.php'); and in the above examples/code change getlastmod() to $myfile and it will work for you.
| Description | String | Example |
| Year, Full Digits | Y | 2000 |
| Year, Abbreviated | y | 00 |
| Month, Full Text | F | February |
| Month, Appreviated | M | Feb |
| Month, Numerical | m | 2 |
| Day of week | l | Friday |
| Day , abbreviated | D | Fri |
| Day of month, Numberical | d | 17 |
| Day of year, numerical | z | 48 |
| Hours, 24 hour | H | 23 |
| Hours, 12 hour | h | 11 |
| Minutes, Numberical | i | 21 |
| Seconds, Numberical | s | 59 |
| Seconds, Since Epoch | U | 924353322 |
| AM or PM | A | AM |
| am or pm | a | am |
that's about itstill have questions? if so, let me know. basically, do what's best for you. odds are you'll just copy on of the above examples and use, great! copying and using lastmodified.inc might also be useful depending on your taste. good luck in all that you do. oh and of course for good measure :
|