What is the difference between using filectime() and header() in PHP?

The difference between using filectime() and header() in PHP is that filectime() retrieves the last change time of a file, while header() is used to send a raw HTTP header to the client. If you need to check the last change time of a file before sending it to the client, you can use filectime() to get the timestamp and then use header() to send the file with the appropriate headers.

$file = 'example.txt';

if (file_exists($file)) {
    $lastChangeTime = filectime($file);
    
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $lastChangeTime) . ' GMT');
    
    readfile($file);
} else {
    header("HTTP/1.0 404 Not Found");
    echo 'File not found.';
}