我有以下简单的HTML文件。我每晚在预先指定的时间更新文件my_image.png
,我希望网站强制刷新浏览器。 但是,下面的rand()
技巧不起作用。如何强制刷新?
<html>
<head>
</head>
<body>
<center>
<?php
$fullpath = "/path/to/my_image.png";
echo "<img src='$fullpath?=<?php =rand(3,32000)?>' HEIGHT='700' />"
?>
<br>
See the chart above
</center>
</body>
</html>
我假设你只是盲目地复制粘贴了代码。好吧,PHP 不会在纯字符串中执行 php 代码<?php
。
使用字符串连接 ( .
)。
echo "<img src='$fullpath?" . rand(3,32000) . "' .....";
注意:rand
将强制(很有可能)在每次页面加载时重新加载。如果您每天更新图像(假设您在午夜更新),请将日期放在那里。
你应该这样做。
echo "<img src='$fullpath?=".rand(3,32000)."' HEIGHT='700' />";