/** * Sends and handles a lastmod header. * * @param int|null $unix_ts The last modification date as a UNIX timestamp * @param bool $exit If TRUE, terminates the script * @return array|null Array of sent HTTP status and the lastmod header, or NULL * @package Pref */ function handle_lastmod($unix_ts = null, $exit = true) { if (get_pref('send_lastmod') && get_pref('production_status') == 'live') { $unix_ts = get_lastmod($unix_ts); // Make sure lastmod isn't in the future. $unix_ts = min($unix_ts, time()); // Or too far in the past (7 days). $unix_ts = max($unix_ts, time() - 3600 * 24 * 7); $last = safe_strftime('rfc822', $unix_ts, 1); header("Last-Modified: {$last}"); header('Cache-Control: no-cache'); $hims = serverSet('HTTP_IF_MODIFIED_SINCE'); if ($hims and @strtotime($hims) >= $unix_ts) { log_hit('304'); if (!$exit) { return array('304', $last); } txp_status_header('304 Not Modified'); // Some mod_deflate versions have a bug that breaks subsequent // requests when keepalive is used. dropping the connection // is the only reliable way to fix this. if (!get_pref('lastmod_keepalive')) { header('Connection: close'); } header('Content-Length: 0'); // Discard all output. while (@ob_end_clean()) { } exit; } if (!$exit) { return array('200', $last); } } }
function handle_lastmod($unix_ts = NULL, $exit = 1) { global $prefs; extract($prefs); if ($send_lastmod and $production_status == 'live') { $unix_ts = get_lastmod($unix_ts); # make sure lastmod isn't in the future $unix_ts = min($unix_ts, time()); # or too far in the past (7 days) $unix_ts = max($unix_ts, time() - 3600 * 24 * 7); $last = safe_strftime('rfc822', $unix_ts, 1); header("Last-Modified: {$last}"); header('Cache-Control: no-cache'); $hims = serverset('HTTP_IF_MODIFIED_SINCE'); if ($hims and @strtotime($hims) >= $unix_ts) { log_hit('304'); if (!$exit) { return array('304', $last); } txp_status_header('304 Not Modified'); # some mod_deflate versions have a bug that breaks subsequent # requests when keepalive is used. dropping the connection # is the only reliable way to fix this. if (empty($lastmod_keepalive)) { header('Connection: close'); } header('Content-Length: 0'); # discard all output while (@ob_end_clean()) { } exit; } if (!$exit) { return array('200', $last); } } }
function handle_lastmod($unix_ts = NULL, $exit = 1) { global $prefs; extract($prefs); if ($send_lastmod and $production_status == 'live') { $unix_ts = get_lastmod($unix_ts); # make sure lastmod isn't in the future $unix_ts = min($unix_ts, time()); # or too far in the past (7 days) $unix_ts = max($unix_ts, time() - 3600 * 24 * 7); $last = safe_strftime('rfc822', $unix_ts, 1); header("Last-Modified: {$last}"); header('Cache-Control: no-cache'); $hims = serverset('HTTP_IF_MODIFIED_SINCE'); if ($hims and @strtotime($hims) >= $unix_ts) { log_hit('304'); if (!$exit) { return array('304', $last); } txp_status_header('304 Not Modified'); # header('Connection: close'); header('Content-Length: 0'); # discard all output while (@ob_end_clean()) { } exit; } if (!$exit) { return array('200', $last); } } }