Sending Last-Modified and handling HTTP_IF_MODIFIED_SINCE using PHP

// last update date in unix time format
$lastModified = strtotime('2022-06-18 19:01:58');

// last visit date sent by the client
$ifModified = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'] ?? '', 5));

if ($ifModified && $ifModified >= $lastModified) {
    //  page not modified
    header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
    exit;
}

header('Last-Modified: ' . gmdate("D, d M Y H:i:s \G\M\T", $lastModified));

Get page last modification date, check for If-Modified-Since, if so, return 304 Not Modified and stop script, otherwise generate Last-Modified header code>.