Jump to content

filemtime returns folder date


EdMullen

Recommended Posts

I just noticed something while updating one of the sites I manage.

I use this code in the footer that is included in every page on the site:

<p>
<?php
$current_file_name = ($_SERVER['REQUEST_URI']);
$current_path = ($_SERVER['DOCUMENT_ROOT']);
$full_name = $current_path.$current_file_name;
$last_modified = filemtime($full_name);
print("This page last changed: ");
print(date("F j, Y - h:i A", $last_modified));
?>
</p>

However, here's what I found a tad odd.  If you go to:

http://westminsteratcrabapple.com/index.php

you get the correct modification date/time.  But, if you go to:

http://westminsteratcrabapple.com/

it shows a different date/time, which is of the folder, not imdex.php.

Any thoughts appreciated.

 

Link to comment
Share on other sites

Simple, $_SERVER['REQUEST_URI'] returns the value in the URL. If the URL includes the path to the file, then it includes the file. If the URL only includes the path to a folder and the webserver is picking a default file,then the file is not included in the value.

Link to comment
Share on other sites

That point needs emphasis: it contains exactly everything in the URL starting with the path. That means it includes the path, "filename", and the query string. And whatever else I may decide to type in there.

 

What you're looking for is REQUEST_FILENAME or SCRIPT_FILENAME. That's an actual file.

 

[edit] Are you copy/pasting this code in all the files? Use the __FILE__ constant instead.

$last_modified = filemtime(__FILE__);
Edited by requinix
Link to comment
Share on other sites

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.