EdMullen Posted April 26, 2013 Share Posted April 26, 2013 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.phpyou 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 26, 2013 Share Posted April 26, 2013 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. Quote Link to comment Share on other sites More sharing options...
requinix Posted April 26, 2013 Share Posted April 26, 2013 (edited) 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 April 26, 2013 by requinix Quote Link to comment 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.