Jump to content

Errors in date last modified


snorky

Recommended Posts

When I run either of the code snippets below, the browser returns

 

Page Last Updated: 12.31.1969

 

/* format of date display */

$fmt_ymd = "m.d.Y";		

/* date page was last modified */

      $file_last_modified = date(filemtime($_SERVER['SCRIPT_FILENAME'])); 	

/* display foooter */

$last_modified = date($fmt_ymd,$file_last_modified);
echo("   Page Last Updated: " . $last_modified);

or

/* format of date display */

$fmt_ymd = "m.d.Y";		

/* date page was last modified */

   $file_last_modified = filemtime("$DOCUMENT_ROOT$PHP_SELF"); 	

/* display foooter */

$last_modified = date($fmt_ymd,$file_last_modified);
echo("   Page Last Updated: " . $last_modified);

 

Trust me - the page was not last modified 40 years ago. All pages involved were modified today.

 

I get the same results on different servers, one with php 5.2.6, the other with 4.4.4

Link to comment
https://forums.phpfreaks.com/topic/187174-errors-in-date-last-modified/
Share on other sites

$fmt_ymd = "m.d.Y";
echo $_SERVER['SCRIPT_FILENAME'] , "created ";
echo date($fmt_ymd, filemtime($_SERVER['SCRIPT_FILENAME']));

worked fine for me

 

i'm assuming your having trouble because the following

/* date page was last modified */

      $file_last_modified = date(filemtime($_SERVER['SCRIPT_FILENAME'])); 	

/* display foooter */

$last_modified = date($fmt_ymd,$file_last_modified);
echo("   Page Last Updated: " . $last_modified);

applies the date function twice, and the first time the usage was incorrect

In your first script this is wrong:

 

$file_last_modified = date(filemtime($_SERVER['SCRIPT_FILENAME']));

 

and should be:

 

$file_last_modified = filemtime($_SERVER['SCRIPT_FILENAME']);

 

In the second script what does $DOCUMENT_ROOT and $PHP_SELF output?

 

var_dump($DOCUMENT_ROOT, $PHP_SELF, $DOCUMENT_ROOT$PHPSELF);

 

I'm assuming that in both cases your code returned 0 or -1 for time which results in somewhere around 1970 (unix epoch)

Thank you your code should be:

 

/* format of date display */

$fmt_ymd = "m.d.Y";		

/* date page was last modified */

      $file_last_modified = filemtime($_SERVER['SCRIPT_FILENAME']);

/* display foooter */

$last_modified = date($fmt_ymd,$file_last_modified);
echo("   Page Last Updated: $last_modified");

 

and

 

/* format of date display */

$fmt_ymd = "m.d.Y";		

/* date page was last modified */

   $file_last_modified = filemtime($_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF']);

/* display foooter */

$last_modified = date($fmt_ymd,$file_last_modified);
echo("   Page Last Updated: $last_modified");

 

What does this now give you?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.