使用标头位置和 IE9 缓存进行重定向的问题
我在 IE9 中使用 PHP 标头位置时遇到问题。
对于电子商务网站,我使用 /cart/add/id-of-product.htm (/cart/add/233.htm) 等链接将产品添加到购物车。其后面的页面将产品添加到购物车并将用户重定向到/cart.htm。 FF 中一切都很完美。它甚至可以在 IE9 中运行,直到有人尝试再次将相同的产品添加到购物车。 IE“认为”他可以直接进入 /cart.htm 页面并跳过我尝试将产品添加到购物车的代码。 IE 会以某种方式缓存有关重定向的信息,但为什么呢? “添加到购物车”按钮后面的链接清楚地显示了链接 /cart/add/233.htm,但是如果您单击它,它只会跳过该页面...我尝试添加一个 ?r=random-number (/cart /add/233.htm?263663746) 后面,但这并不重要。
有谁知道如何避免这种情况?我想在用户将产品添加到购物车后重定向用户,但如何避免 IE 的这种情况呢?
感谢您抽出时间!
I have a problem using PHP header location with IE9.
For a e commerce website I add products to a cart using a link like /cart/add/id-of-product.htm (/cart/add/233.htm). The page behind it adds the product to the cart and redirects the user to /cart.htm. Everything works perfect in FF. It even works in IE9, until someone tries to add the same product to the cart again. IE 'thinks' he can go directly to the /cart.htm page and skip my code where I try to add the product to the cart. Somehow IE caches information about the redirect, but why? The link behind the 'add to cart' button clearly shows the link /cart/add/233.htm, but if you click it it just skips the page... I tried to put a ?r=random-number (/cart/add/233.htm?263663746) behind it, but this does not matter.
Does anyone know how to avoid this? I want to redirect the user after they added a product to the cart, but how do I avoid this IE thing?
Thanks for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Internet Explorer 按照 RFC 的允许缓存 HTTP/3xx 重定向。如果您不希望缓存给定的重定向,则需要使用不带未来过期时间或 max-age 的 HTTP/302。您明确不想使用 HTTP/301。
(如果你做得正确的话,你在 URL 中放入随机查询字符串的尝试将会起作用,但是你在那里做错了。)
Internet Explorer caches HTTP/3xx redirects as allowed by the RFC. If you don't want a given redirect to be cached, you need to use a HTTP/302 without a future Expires or max-age. You explicitly don't want to use a HTTP/301.
(Your attempt to put a random query string in the URL would have worked if you had done it properly, but you did something wrong there.)