4

I have a php script with is used to rotate banner images on a site.

Under Firefox/IE page refreshes will make another request and a different image will be returned.

Under Chrome, the request seems to be cached and only opening the page in a new tab will cause it to actually query the script.

I believe this used to work in older versions of chrome, I've tried a few different types of redirect codes all with the same result.

Any tips?

<img class="banner" src="/inc/banner.php" alt="">

~$ cat /var/www/inc/banner.php 
<?php

header("HTTP/1.1 302 Redirect");
header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");

//header('HTTP/1.1 307 Temporary Redirect');
//header("expires: none");
//header("expires: max");
//header("Cache-Control: public");

$folder = '../img/banner/';

$exts = 'jpg jpeg png gif';

$files = array(); $i = -1;
if ('' == $folder) $folder = './';

$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
++$i;
}
}
}
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); 
flush();
?>

curl output;

~$ curl -I -k https://example.net/inc/banner.php
HTTP/1.1 302 Redirect
Server: nginx/1.1.14
Date: Fri, 24 Feb 2012 03:23:46 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.3.10-1ubuntu1
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Location: ../img/banner/2.jpg
Thermionix
  • 907
  • 2
  • 15
  • 28
  • It doesn't look like your `Cache-Control` header stuck? The `max-age` and `must-revalidate` have disappeared. An `Expires:` header set to the past is worth a try, too. – Shane Madden Feb 24 '12 at 06:24
  • Ah ignore that, had updated the conf but not curl output. I've tried with expires:none which didn't help :( – Thermionix Feb 24 '12 at 22:23
  • `Expires` must be a date; set it to the past. Have you cleared Chrome's cache between tests? – Shane Madden Feb 24 '12 at 22:26
  • I've been trying chrome on multiple machines/platforms and clearing cache, all with the same result – Thermionix Feb 29 '12 at 06:37

3 Answers3

8

Bug in chrome: http://code.google.com/p/chromium/issues/detail?id=103458

MEM76
  • 81
  • 1
  • 2
1

On my homepage i had the top frames filename to be: banner.php it did not show up in Google Chrome, worked OK in all the other browswer... I was looking for errors in the code for hours, then i changed the filename and the link from the frameset to mybanner.php and it worked also in Google chrome!

0

Accordin to W3C (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3) "This response is only cacheable if indicated by a Cache-Control or Expires header field". Try using a 301 "Moved Permanently"