...

View Full Version : How do I add a "This page was last updated on.." to my site?



moss2076
11-03-2008, 07:25 PM
Is there a method of automatically adding a "this page was last update on..." to my site?

The BBC use one on their site http://news.bbc.co.uk/

I know I can just type in the date and time, but I was wondering if there is an automated method for whenever I update anything?

Scriptet
11-03-2008, 08:18 PM
Yes this is possible via PHP, and common amongst many CMS (content-management-systems).

You can either learn PHP to retrieve a value on when a document is updated or use an already available Blogging system (Wordpress/Blogger) of some sort which it is common.

tomws
11-03-2008, 08:32 PM
Dreamweaver had a function to do this once upon a time, if you happen to be using that. I don't use it any more, though, so don't know if it's still there.

Also, PHP's filemtime() (http://us3.php.net/manual/en/function.filemtime.php) would work nicely if your server is PHP friendly. The others probably have something similar.

owt200x
11-04-2008, 03:28 AM
this is from http://us3.php.net/manual/en/function.filemtime.php


<?php
// outputs e.g. somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>

Major Payne
11-05-2008, 03:02 AM
Simple JavaScript:
<script type="text/javascript">

function lastModified() {
var modiDate=new Date(document.lastModified)
var showAs=modiDate.getDate()+ "-" +(modiDate.getMonth()+1)+ "-" +modiDate.getYear();
return showAs }

function GetTime() {
var modiDate = new Date();
var Seconds

if (modiDate.getSeconds() < 10)
{
Seconds = "0" + modiDate.getSeconds();
} else {
Seconds = modiDate.getSeconds();
}

var modiDate = new Date();
var CurTime = modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds
return CurTime }

document.write ("This page was last updated on ")
document.write (lastModified() + " @ " + GetTime() );

</script>

Goes in between body tags, but if using it as an external js file, then link and style where you want it to appear.

moss2076
11-06-2008, 09:02 AM
Simple JavaScript:
<script type="text/javascript">

function lastModified() {
var modiDate=new Date(document.lastModified)
var showAs=modiDate.getDate()+ "-" +(modiDate.getMonth()+1)+ "-" +modiDate.getYear();
return showAs }

function GetTime() {
var modiDate = new Date();
var Seconds

if (modiDate.getSeconds() < 10)
{
Seconds = "0" + modiDate.getSeconds();
} else {
Seconds = modiDate.getSeconds();
}

var modiDate = new Date();
var CurTime = modiDate.getHours() + ":" + modiDate.getMinutes() + ":" + Seconds
return CurTime }

document.write ("This page was last updated on ")
document.write (lastModified() + " @ " + GetTime() );

</script>

Goes in between body tags, but if using it as an external js file, then link and style where you want it to appear.

This code just updates the time whenever the Refresh button in a browser is clicked, so it isnt a true time-stamp. But thankyou for your reply :)

j05hr
11-06-2008, 01:52 PM
<script>
document.write('text goes here')
</script>
<script>
var modifieddate=document.lastModified
document.write(modifieddate)
</script>


As mentioned before goes in the body tags, should work :thumbsup:

Donkey
11-06-2008, 03:28 PM
Surely the easiest way is to use server side includes?

e.g. for your index page rename the page "index.shtml" then add the following code

Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="index.shtml" -->.
This will output in the following format:

Last modified 06 November 2008.

owt200x
11-06-2008, 08:13 PM
felt the need to repost, since it seems everyone skipped my first post :)

and i changed it so it outputs "This page was last updated on November 06 2008 14:11:22" or whatever date and time the file was last changed.


<?php
// outputs e.g. This page was last updated on November 06 2008 14:11:22

$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "This page was last updated on " . date ("F d Y H:i:s", filemtime($filename));
}
?>

jlhaslip
11-07-2008, 06:46 AM
<?php
// outputs e.g. This page was last updated on November 06 2008 14:11:22

echo "This page was last updated on " . date ("F d Y H:i:s", filemtime($_SERVER['SCRIPT_FILENAME']));

?>

moss2076
11-07-2008, 10:16 AM
Surely the easiest way is to use server side includes?

e.g. for your index page rename the page "index.shtml" then add the following code

Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="index.shtml" -->.
This will output in the following format:

I had been using Dreamweavers code up until now -

<!-- #BeginDate format:fcAm1a -->Thursday, November 6, 2008 11:33 PM<!-- #EndDate -->, this works, but it only saves the date and time when index.html is saved on my computer. It doesnt save the date and time when I update the page to my server, which is what I want.

I havent tried the other examples that have been posted as Im waiting for new hosting, so hopefully I will be able to give them a go later today.

Many thanks everyone for your replies.

Donkey
11-07-2008, 11:00 AM
It doesnt save the date and time when I update the page to my server, which is what I want.This is nothing to do with dreamweaver? The code I posted does what you want provided your host allows server side includes. Most do.

owt200x
11-07-2008, 07:23 PM
the post i made above works perfectly

moss2076
11-07-2008, 08:22 PM
Surely the easiest way is to use server side includes?

e.g. for your index page rename the page "index.shtml" then add the following code

Last modified <!--#config timefmt="%d %B %Y" --><!--#flastmod file="index.shtml" -->.
This will output in the following format:

You are totally correct. I have changed the %d %B %Y to just %c which gives 11/07/08 20:27:49.

Many thanks :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum