PHP URL字符串以避免浏览器缓存 [英] PHP URL string to avoid browser caching
问题描述
我的网站被设计成一个有趣的图片网站,当用户点击随机按钮时,同一页面上的PHP代码会生成新的随机图片,这就是它应该起作用的方式。但是,我必须按下F5按钮才能获取新图像。
My site is designed to be a funny picture site, when the user hits the random button a PHP code on the same page generates a new random picture, this is how it is supposed to work. I however have to hit the F5 button to get a new image.
我在阅读另一个问题,人们在末尾使用获取日期和获取时间查询字符串避免浏览器缓存的链接,但是我无法终生解决。
I was reading on another question that people use a get date and get time query string generated at the end of the link to avoid browser caching, I however can not figure it out for the life of me.
我对php不太满意,所以请讲一下了解基本的网页结构。谢谢!
I am not very good with php so please speak as if I only know the basic webpage structure. Thank you!
推荐答案
您所描述的内容称为缓存破坏器,通常是附加在URL后面的随机字符串或时间戳记。当您引用图像时,应像这样:
What you are describing is called a cache breaker and is usually a random string or a timestamp appended to the url. When you are referencing your image, prepend it like this:
echo get_random_image_url() . '?' . time();
这将导致网址看起来像这样:
This will result in an url looking like this:
http://your.server.com/random.jpg?1355862360
注意: get_random_image_url
只是一个例子,但是我敢肯定您的想法。
Note: get_random_image_url
is just an example, but i'm sure you get the idea.
此线程可能是您感兴趣的:如何强制网络浏览器不缓存图像。
This thread may be of interest: How to force a web browser NOT to cache images.
这篇关于PHP URL字符串以避免浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!