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

强颜欢笑 提交于 2019-12-03 12:33:48

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);

My idea, make change on server configuration, to execute different extension rather then only PHP. for printing images when you use img tag with source of php file to render image. use different extension such as getimage.iphp. Include in your .htaccess settings with cache control of file with extension .iphp

Finally use header inside your image generation function to set expiry of individual image file.

Its bit theory but might be useful as idea to implement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!