gpt4 book ai didi

html - 防止用户返回并查看之前提交的表单 Rails

转载 作者:行者123 更新时间:2023-12-04 16:09:52 26 4
gpt4 key购买 nike

我有一个付款页面,当用户提交时,它会捕获付款并指向感谢页面。问题是当用户点击返回时,浏览器会将他们带回之前提交的页面,其中包含支付表单和所有内容。

如何阻止用户访问上一页?

谢谢

最佳答案

@James,将此方法放入您的应用程序 Controller 中,并在 before_action 回调中调用此方法,例如 -

before_action :set_cache_buster

然后在 protected 方法中定义 Action ,如 ->

protected

def set_cache_buster
response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "#{1.year.ago}"
end

为此,我们只需要使用适当的 HTTP header 禁用浏览器缓存。这是 secret :

Cache-Control: no-cache, max-age=0, must-revalidate, no-store

单独来看,这些 Cache-Control 属性中的每一个似乎都可以防止缓存。实际上,在大多数浏览器中,no-cache 和 no-store 通常是可以互换的。但是,特别是对于后退按钮缓存,Firefox 仅在指定 no-store 时才会禁用此缓存。为了安全起见并保证跨浏览器兼容性,您应该使用所有四个属性。

更多信息见链接 - Difference between Pragma and Cache-Control headers?

具体页面:

在特定页面上添加该回调,唯一的选项如下:

before_action :set_cache_buster, only: [:your_action_name]

关于html - 防止用户返回并查看之前提交的表单 Rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30402183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com