Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.