Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**\
- * @param string $last_modified
- * @param string $etag
- * @return bool
- * @desc original from http://www.nvb.ru/tulz/last~modified~and~etag/
- */
- function getIsModified($last_modified = '', $etag = '')
- {
- global $_SERVER;
- $refresh = TRUE;
- if ($last_modified == '') $last_modified = time();
- $none_match = (isset($_SERVER['HTTP_IF_NONE_MATCH']))
- ? $_SERVER['HTTP_IF_NONE_MATCH'] : '';
- $modified_since = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
- ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : '';
- $since = 0;
- if ($modified_since) { // BUG: NetScape sends ";lenght = xxx" after the date
- $arraySince = explode(';', $modified_since);
- $since = strtotime($arraySince[0]);
- }
- switch (TRUE) {
- case (!$none_match && $modified_since):
- if ($since <= time() && is_int($since) && $since >= $last_modified) return FALSE;
- break;
- case ($none_match):
- if ($modified_since) { // Проверка и по If-None-Match, и по If-Modified-Since
- if ($since > time() || !is_int($since) || $since < $last_modified)
- break; // Файл в кеше клиента устарел по If-Modified-Since
- }
- // Проверку If-Modified-Since, если она была - прошли. Проверка по If-None-Match:
- if ($etag == '') break;
- $INM = split('[,][ ]?', $none_match);
- foreach ($INM as $enity)
- if ($enity == '' || $etag == '' || $enity == '*') return FALSE; // 304 Not Modified
- break;
- default:
- ; // Conditional Get не задан - просто отдаем страницу.
- }
- return TRUE; // Страница изменилась (200 ОК)
- }
- $is_send_last_modified = false;
- function LastModified($last_modified = null) {
- global $is_send_last_modified;
- if (!$last_modified) {
- $last_modified = time();
- }
- $gmt_mtime=gmdate('r', $last_modified);
- if (!$is_send_last_modified) {
- $gmt_mtime = str_replace('+0000', 'GMT', $gmt_mtime);
- header('Last-Modified: ' . $gmt_mtime);
- }
- $is_send_last_modified = true;
- if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
- if (!getIsModified($last_modified)) {
- header('HTTP/1.1 304 Not Modified');
- header('Content-Length: 0');
- exit();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement