PHP Shuffle Function无法在IE8和Chrome中刷新

问题描述

| 我正在使用以下PHP shuffle功能代码显示图像列表:
    <?PHP
$images = array();
$images[\'image1\'] = array(\"id\" => \"sales1\",\"href\" => \"#salesperson1\",\"src\" => \"salesteam/salesteam-jessie.png\");
$images[\'image2\'] = array(\"id\" => \"sales2\",\"href\" => \"#salesperson2\",\"src\" => \"salesteam/salesteam-anthony.png\");
$images[\'image3\'] = array(\"id\" => \"sales3\",\"href\" => \"#salesperson3\",\"src\" => \"salesteam/salesteam-nicole1.png\");
$images[\'image4\'] = array(\"id\" => \"sales4\",\"href\" => \"#salesperson4\",\"src\" => \"salesteam/salesteam-kevin.png\");
$images[\'image5\'] = array(\"id\" => \"sales5\",\"href\" => \"#salesperson5\",\"src\" => \"salesteam/salesteam-christi.png\");
$images[\'image6\'] = array(\"id\" => \"sales6\",\"href\" => \"#salesperson6\",\"src\" => \"salesteam/salesteam-thomas.png\");
$images[\'image7\'] = array(\"id\" => \"sales7\",\"href\" => \"#salesperson7\",\"src\" => \"salesteam/salesteam-melissa.png\");
$images[\'image8\'] = array(\"id\" => \"sales8\",\"href\" => \"#salesperson8\",\"src\" => \"salesteam/salesteam-nicole2.png\");
shuffle($images);
foreach ($images as $singleimage) {
$singleid = $singleimage[\'id\'];
$singlehref = $singleimage[\'href\'];
$singlesrc = $singleimage[\'src\'];
echo \"<li><a id=\\\"$singleid\\\" href=\\\"$singlehref\\\"><img src=\\\"$singlesrc\\\" /></a></li>\";
}
?> 
在IE8或Chrome浏览器中刷新时不起作用。在Firefox中确实可以正常工作。这是缓存问题吗?     

解决方法

您可以通过http标头强制不缓存
<?PHP
header( \'Expires: Sat,26 Jul 1997 05:00:00 GMT\' );
header( \'Last-Modified: \' . gmdate( \'D,d M Y H:i:s\' ) . \' GMT\' );
header( \'Cache-Control: no-store,no-cache,must-revalidate\' );
header( \'Cache-Control: post-check=0,pre-check=0\',false );
header( \'Pragma: no-cache\' ); 
    ,它来自缓存,应该用作src $ imagesrc。\'?\'。rand(0,999)
echo \"<li><a id=\\\"$singleid\\\" href=\\\"$singlehref\\\"><img src=\\\"$singlesrc?\".rand(0,999).\"\\\" /></a></li>\";