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.';
}
Keywords
Related Questions
- Can you provide a comprehensive tutorial or resource for beginners on form field validation in PHP, including examples and explanations?
- Are there better alternatives to using external programs and MD5 hashes for script security in PHP?
- What are some common challenges faced when trying to implement custom PHP code in a WordPress plugin like Woocommerce?