| 47 | } |
| 48 | |
| 49 | $last_modified = gmdate( 'D, d M Y H:i:s', filemtime( $file ) ); |
| 50 | $etag = '"' . md5( $last_modified ) . '"'; |
| 51 | header( "Last-Modified: $last_modified GMT" ); |
| 52 | header( 'ETag: ' . $etag ); |
| 53 | header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 100000000 ) . ' GMT' ); |
| 54 | |
| 55 | // Support for conditional GET - use stripslashes() to avoid formatting.php dependency. |
| 56 | $client_etag = isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ? stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) : false; |
| 57 | |
| 58 | if ( ! isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { |
| 59 | $_SERVER['HTTP_IF_MODIFIED_SINCE'] = false; |
| 60 | } |
| 61 | |
| 62 | $client_last_modified = trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); |
| 63 | // If string is empty, return 0. If not, attempt to parse into a timestamp. |
| 64 | $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0; |
| 65 | |
| 66 | // Make a timestamp for our most recent modification... |
| 67 | $modified_timestamp = strtotime( $last_modified ); |
| 68 | |
| 69 | if ( ( $client_last_modified && $client_etag ) |
| 70 | ? ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) |
| 71 | : ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) |
| 72 | ) { |
| 73 | status_header( 304 ); |
| 74 | exit; |