How can PHP headers like Last-Modified be effectively utilized to control browser caching for PHP scripts?

To control browser caching for PHP scripts, you can utilize PHP headers like Last-Modified to specify when a resource was last modified. This allows the browser to determine if it needs to request a new version of the resource or if it can use a cached version. By setting the Last-Modified header to the last modification time of the resource, you can effectively control browser caching for PHP scripts.

<?php
$last_modified_time = filemtime(__FILE__);
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $last_modified_time) . " GMT");
header("Cache-Control: public");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT"); // Cache for 1 hour