Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
Specify a cache validator for images created by imagejpeg/imagepng functions

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

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
</IfModule>

.. and ..

<IfModule mod_headers.c>
    <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
        Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT"
    </FilesMatch>
</IfModule>

But, it will be effective for real JPG or PNG files. However, the question is, how to specify cache validator for images that are built with PHP codes and imagejpeg/imagepng functions on fly? (above codes are not effective for them)

P.S: I have tried to simulate the URL of image created by PHP like a real image using .htaccess file (e.g: http://example.com/1.jpg, which is generated by PHP file and is not a real .jpg image), but still receiving cache validator warning.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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);
over 4 years ago · Santiago Trujillo Relatório

0

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.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda