Including last modified dates?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
JediBookworm
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Jun 30, 2003 3:54 pm
Location: Canada
Contact:

Including last modified dates?

Postby JediBookworm » Sun Aug 31, 2003 10:25 pm

Hi,

I have many PHP pages that all include a page called include.inc

In include.inc, i've put the code needed to display the last modified date of a file

But how do i make it so that the code displays the last modified date of each including file rather than the included file (include.inc)?

thanks

P.S. because if i try the normal way of getting the filename it is the filename of the script executed (include.inc), while i want the constantly-changing filename of the file (page1.php, etc.) that includes include.inc

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: Including last modified dates?

Postby swirlee » Sun Aug 31, 2003 10:39 pm

JediBookworm wrote:But how do i make it so that the code displays the last modified date of each including file rather than the included file (include.inc)?


When you use getlastmod() to get the last-modified date of the current file, it will always return the last-modified date of the including file. To demonstrate:

Code: Select all

<? /*** test.php ***/
echo 'test.php - ' . getlastmod() . "<br />\n";
include '2.php';
?>


Code: Select all

<? /*** 2.php ***/
echo '2.php - ' . getlastmod();
?>


Now, if I load test.php in my browser, it outputs the following:
test.php - 1062398109
2.php - 1062398109

Even if I modified 2.php at a much later date, it will always display the last-modified date for the calling page, test.php. That sounds like what you want.

If you're trying to get the last-modified date for an included page (or any file other than the requested file), you have to use filemtime('file.php'). So if I changed 2.php to this:

Code: Select all

<? /*** 2.php ***/
echo '2.php - ' . filemtime('2.php');
?>


But didn't modify test.php at all, the output is now this:
test.php - 1062398109
2.php - 1062398458

User avatar
JediBookworm
New php-forum User
New php-forum User
Posts: 13
Joined: Mon Jun 30, 2003 3:54 pm
Location: Canada
Contact:

Postby JediBookworm » Sun Aug 31, 2003 10:44 pm

When i first asked about last modified file times they told me about filemtime() but now i know there's also getlastmod()

Thanks for your explanation! :D

P.S. Oh, I have one more question. How do you format the time for getlastmod()? Is it the same as formatting date() functions? This is to say converting to GMT. Also, is there a way to fix daylight saving time differences? Thx

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Sun Aug 31, 2003 11:02 pm

JediBookworm wrote:P.S. Oh, I have one more question. How do you format the time for getlastmod()? Is it the same as formatting date() functions? This is to say converting to GMT. Also, is there a way to fix daylight saving time differences? Thx


That's two questions. The first is answered in the documentation, where you should have looked first. The second is a little trickier. Try date() or localtime(), which both have arguments for DST.


Return to “PHP coding => General”

Who is online

Users browsing this forum: landi and 3 guests