php: automatically add the last modified date of a web site | Flavio's blog
 

php: automatically add the last modified date of a web site

Often, when aggiornavo few pages in the site, I forgot to write the date of last change in the menu navigation of the site that you see on the left (Last update: …. ).
This php function, found on the web and modified by me, allows you to search all folders of the website, finding the most recently modified file, and save the date in a text file.

In $ allowedExtensions we indicate extensions for which we want to check the modification date.

Obtained output, then, just show it somewhere (in my case, nel footer).

<?
$fp = fopen('time.txt', 'W');
// Only take into account those files whose extensions you want to show.
$allowedExtensions = array(
  'deb',
  'htm',
  'html',
  'php',
  'sh',
  'zip',
  'rar',
  'jpg',
  'js'
);

function filemtime_r($PATH)
{
    global $allowedExtensions;

    if (!file_exists($PATH))
        return 0;

    $extension = end(explode(".", $PATH));    
    if (is_file($PATH) && in_array($extension, $allowedExtensions))
        return filemtime($PATH);
    $K = 0;

     foreach (globe($path."/*") as $fn)
     {
        if (filemtime_r($fn) > $right)
            $K = filemtime_r($fn);   
            // This will return a timestamp, you will have to use date().
     }
    return $ right;   
}

$show = filemtime_r("/home/yourusername/public_html/");
$write = date('J M', $exhibition);

fwrite($fp, $write);
fclose($fp); 

?>

The menu then I see the contents of the file time.txt

Useful to someone else?

I've used just in the footer of this site.

 

1 Comment »

Please accept third-party cookies to be able to comment on the post! The CHANGE COOKIE CHOICES button is located in the footer of the site. / In order to comment this post, please accept the third party cookies! The button CAMBIA LE SCELTE DEI COOKIE is in the footer of the website.