snorky Posted January 4, 2010 Share Posted January 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/187174-errors-in-date-last-modified/ Share on other sites More sharing options...
mikesta707 Posted January 4, 2010 Share Posted January 4, 2010 $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 Quote Link to comment https://forums.phpfreaks.com/topic/187174-errors-in-date-last-modified/#findComment-988392 Share on other sites More sharing options...
ignace Posted January 4, 2010 Share Posted January 4, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/187174-errors-in-date-last-modified/#findComment-988395 Share on other sites More sharing options...
snorky Posted January 4, 2010 Author Share Posted January 4, 2010 var_dump($DOCUMENT_ROOT,$PHP_SELF,$DOCUMENT_ROOT.$PHP_SELF); throws NULL NULL string(0) "" Quote Link to comment https://forums.phpfreaks.com/topic/187174-errors-in-date-last-modified/#findComment-988461 Share on other sites More sharing options...
ignace Posted January 6, 2010 Share Posted January 6, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/187174-errors-in-date-last-modified/#findComment-989634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.