Liz Ainslie
Liz Ainslie

Reputation: 31

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

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?

Upvotes: -1

Views: 283

Answers (1)

Syed Waqas Bukhary
Syed Waqas Bukhary

Reputation: 5340

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.

Upvotes: 1

Related Questions