How do I find the last access time of a file in php

256 Views Asked by At

I need to know when the last time a file (main.html) was accessed using PHP. I want the user be able to see when the last time a different user accessed the page. How can I do this using PHP?

1

There are 1 best solutions below

0
Syed Waqas Bukhary On BEST ANSWER

The function fileatime is used to get the last access time of the given file.

$filename = 'somefile.txt';
    if (file_exists($filename)) {
        echo "$filename was last accessed: " . date("F d Y H:i:s.", fileatime($filename));
    }

// outputs e.g.  somefile.txt was last accessed: December 29 2002 22:16:23.