304 Not Modified issue

前端 未结 3 572
囚心锁ツ
囚心锁ツ 2021-01-07 17:38

Sorry for the probably wrong title. I am writing some code to handle If-Modified-Since and If-None-Match requests as part of caching. Everything works perfect except for tha

3条回答
  •  青春惊慌失措
    2021-01-07 17:57

    Try this code:

    $last_modified = filemtime($f);
    if(isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
        $expected_modified = strtotime(preg_replace('/;.*$/','',$_SERVER["HTTP_IF_MODIFIED_SINCE"]));
        if($last_modified <= $expected_modified) {
            header("HTTP/1.0 304 Not Modified");
            exit;
        }
    }
    

提交回复
热议问题