Chrome caching 302 redirects
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
Solution 1:
Bug in chrome: http://code.google.com/p/chromium/issues/detail?id=103458
Solution 2:
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!