Specify a cache validator for images created by imagejpeg/imagepng functions

前端 未结 2 1629
天命终不由人
天命终不由人 2021-02-15 06:53

All we know we can specify a cache validator for images by adding following lines to .htaccess file:


    ExpiresActive On
    Expi         


        
2条回答
  •  抹茶落季
    2021-02-15 07:40

    You can add the PHP code before imagejpeg/imagepng functions:

    function TestModifiedSince($PageTimeStamp, $TextDatePage) {
        if (isset($_SERVER["HTTP_CACHE_CONTROL"])) {return;}
        if (!isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {return;}
        $TestTime=strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]);
        if (($TestTime - $PageTimeStamp) >= 0) {
            header('Last-Modified: '. $TextDatePage, true, 304);
            exit();
        }
    }
    
    #                           hh  mm  ss  MM  DD  YYYY
    $DateUpdateBaseDef = mktime(00, 00, 00, 08, 31, 2009);
    $TimeHeadUpdate = gmdate('D, d M Y H:i:s', $DateUpdateBaseDef).' GMT';
    TestModifiedSince($DateUpdateBaseDef, $TimeHeadUpdate);
    

提交回复
热议问题