Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
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 6: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 6:37

3 Answers 3

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!

share|improve this answer

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"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.