Web Analytics Made Easy -
StatCounter File Datestamp from Server - CodingForum

Announcement

Collapse
No announcement yet.

File Datestamp from Server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Datestamp from Server

    Need a script that gives the datestamp of a file from the server rather than the datestamp of the file in the local cache (which always turns out to be today's date).

    This is the script I've been given:

    // Script Start

    var docdate = new Date(document.lastModified);
    var month = docdate.getMonth();

    if (month == 0) var monthstr = "January";
    if (month == 1) var monthstr = "February";
    if (month == 2) var monthstr = "March";
    if (month == 3) var monthstr = "April";
    if (month == 4) var monthstr = "May";
    if (month == 5) var monthstr = "June";
    if (month == 6) var monthstr = "July";
    if (month == 7) var monthstr = "August";
    if (month == 8) var monthstr = "September";
    if (month == 9) var monthstr = "October";
    if (month == 10) var monthstr = "November";
    if (month == 11) var monthstr = "December";

    var year = docdate.getYear()
    if (year < 1000) {
    year = year + 1900;
    }

    document.write(
    "<span class=update>Updated: "
    + docdate.getDate() + " "
    + monthstr + " "
    //
    + year + " </span>"
    );

    // Script End

    This script gives the date of the file in the local cache rather than the date from the server. Any suggestions?

  • #2
    If you want to use something from server (date, your case) you must use a server-side application not a client-side application (javascript is a client-side language)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    Comment


    • #3
      The "document.lastModified" item is part of a group sometimes used by hackers to gain access to a server. Some ISP's block the entire group rather than putting forth the effort to block the real problems and let through the no-problem items like "document.lastModified." The result is that the server gives no informaiton (null) for this item.

      Internet Explorer takes this null, uses it as-is in the "new Date()" function, and gets the CURRENT date and time on the user's machine. You update a page, check this value, find that it's current, and you're happy. Your visitor checks the value, finds that it is "today," believes that you've recently updated the page, and s/he's happy. But the value is still wrong.

      Netscape takes the null, forces it to be numeric, gets a zero at this point, uses the zero in the "new Date()" funciton, and gets the first midnight of January 1, 1970, GMT. It then adjusts for timezone offset of the user machine and displays the result. For me in the eastern USA, the display says 7:00pm on December 31, 1969.

      WebTV processes similarly to Netscape, but does the timezone correction earlier, may wind up with a negative value to the "new Date()" function, and gets all upset.

      Every other browser that I've tested follows one of the three patterns described above.
      Having said that, I've probably told you more than I know.

      Comment

      Working...
      X