Page last updated..

They have: 238 posts

Joined: May 2002

I'm wondering if I can get a piece of php code which can tell me when a page was last updated/modified? The page filename would have to be stored in a varible because it will be included in all my pages.

I'm also looking for the php page generated in 'x' seconds script. Would it also be possible to round off the number to one decimal place or to the nearest one instead of having: 1.12443576 seconds.

Thanks!

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

I guess that it depends upon what kind of page. If it is a page that comes from a database, you could add a timestamp to the page that changes when the data is updated. Otherwise, you could use the filemtime function in php.

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

<?php
////////////////////////////////////////////////////////////////////////////////
//  Speed Check:
if (!function_exists('exec_speed_check')) {
    function
exec_speed_check(){
        list(
$speed_check_sec, $speed_check_msec) = explode(\" \", microtime());
        return ((float)
$speed_check_sec + (float)$speed_check_msec);
    } #END exec_speed_check()
}
$speed_check_start = exec_speed_check();
////////////////////////////////////////////////////////////////////////////////


// blah
// blah
// blah


////////////////////////////////////////////////////////////////////////////////
// Speed Check:
$speed_check_finish = exec_speed_check();
$speed_check_runtime = $speed_check_finish - $speed_check_start;
echo \"Runtime: \" . number_format(
$speed_check_runtime, 6) . \" seconds\n\";
////////////////////////////////////////////////////////////////////////////////
?>

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 238 posts

Joined: May 2002

Thanks for the help guys Wink

They have: 238 posts

Joined: May 2002

Quote: Originally posted by mairving
I guess that it depends upon what kind of page. If it is a page that comes from a database, you could add a timestamp to the page that changes when the data is updated. Otherwise, you could use the filemtime function in php.

Still need some help; On php.net they have the following code:

<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (
file_exists($filename)) {
    echo \
"$filename was last modified: \" . date (\"F d Y H:i:s.\", filemtime($filename));
}
?>

How could I find out the filename of the current file and store it in the variable $filename so I can include this script on all my pages and have the respective results shown?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try:
$filename = basename($_SERVER['PHP_SELF']);

They have: 238 posts

Joined: May 2002

That worked but I want to modify it further..

Is there any way to show the directory that the file resides in. For example:

blah/home/public_html/help/faq.php

Would it be possible to show that part in bold?

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try $_SERVER['PHP_SELF']

They have: 238 posts

Joined: May 2002

Thanks once again Laughing out loud

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.