Forum Moderators: open

Message Too Old, No Replies

"last modified" shows today's date

I want it to say when I last changed something

         

Eva_Brick

7:17 am on Aug 14, 2005 (gmt 0)

10+ Year Member



On my pages, and pages I've done for friends, I have at the bottom

<p class="credit"><a href="#top">Return to top</a><br><br>

<script type="text/javascript">
<!--
document.write("Last Modified " + document.lastModified)
// -->
</script></p>


This is supposed to say when I last made changes to the page, but on many pages it's giving today's date instead.
I have a different script on some pages, but the same thing is happening with that as well. I looked with IE5.5 as well as FireFox. It seems to be the same; some pages with the save date, others with today's date. I can't see any sort of pattern to it. What have I done wrong?

I don't understand javascript. I just copy things from help pages.

RonPK

9:46 am on Aug 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The script reads the Last Modified header which is sent by the server to the browser together with the content of the page.

It should work fine on static HTML pages, if the server sends a correct Last Modified header. Most servers do, but some don't.

It will normally show today's date on dynamic pages, like PHP or ASP. Such pages are created on the fly, so unless you send a fake Last Modified header, the current timestamp will be sent.

JAB Creations

11:24 am on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're using PHP this will work perfectly...

<?php echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());?>

Dijkgraaf

9:34 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Of course if your PHP contains information comming from a database, you will also want to check the modification dates on the data and serve that up as the last modified date if it has changed after the modification date of the PHP.

Eva_Brick

3:05 am on Aug 16, 2005 (gmt 0)

10+ Year Member



Thank you all. I'm sorry, I did post a thank you yesterday, but I see it hasn't appeared. I suppose I pressed the wrong button yet again.
All of my pages are just static html. The answers are helpful, although some are information for when I do get to php.

RonPK

6:58 am on Aug 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Eva, there's a handy little tool in this board's control panel. Under plugins you will find server headers, which will list the headers your server sends. The response will look like this:
HTTP/1.1 200 OK
Date: Tue, 16 Aug 2005 06:51:06 GMT
Server: Apache
Vary: Accept-Encoding
Last-Modified: Fri, 01 Nov 2002 06:34:32 GMT
[..]

That shows the Last-Modified timestamp that the javascript will use. If it is incorrect, alert the system administrator.

Eva_Brick

1:43 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Thank you, Ron.
I'll do that right now.

Eva_Brick

4:57 am on Aug 20, 2005 (gmt 0)

10+ Year Member



It turned out that it was something to do with server side includes. I'd begun using these for my top bar menu. Luckily I'd only made a few pages that way. When the instruction to parse the includes went into my .htaccess, that stopped the javascript dates from working.
My host said that the solution was simple--just change the last modified date on every page to an include thingy. I want to preserve the original dates; they're a record of my progress in writing pages, for one thing.
In the end I had the line about includes removed from .htaccess, I put the menu bar directly onto each of the new pages, and all is well.
What I would like to know is: would the same thing happen on any host--would the ssi always interfere with my "last modified" dates, or is it just something amiss with my particular host?
At this point I've lost all interest in ssi, but might want to try again one day.