PHP和浏览器的“返回”按钮 - 真正发生了什么 [英] PHP and Browser 'Back' button - what is really hapenning

查看:126
本文介绍了PHP和浏览器的“返回”按钮 - 真正发生了什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的PHP页面执行'REAL'操作。

'REAL'我的意思是执行数据库操作,编写文件,类似的东西,而不仅仅是发送HTML。 b
$ b

当我点击'返回'按钮到我的PHP页面时,假设它是一个GET。


  • 这是否意味着我的PHP代码不一定会在所有浏览器上运行?如果我有一张图片,我希望在每次查询该页面时刷新图片(特别是在'Back'上),我应该怎么做? b
    是只是我还是有内部不喜欢javascript是正常的? (它总是在我看来像一个无法工作的补丁,再加上不是所有人都让javascript工作)。

    我不挑剔,但是它可以认为一个HTTP级别的解决方案是最好的吗?



    谢谢

    解决方案

    div>

    通过POST加载的页面将导致浏览器要求用户重新提交信息以查看页面,从而导致该页面执行的操作再次发生。如果通过GET请求页面并在查询字符串中包含变量,则会发生同样的事情,但是会默默无闻地(不会提示用户再次提醒)。



    最好的工作方式围绕这是使用 POST / REDIRECT / GET模式 。我在一个关于处理我为Authorize.Net编写的付款。希望你能指出正确的方向。

    Assuming my PHP page does 'REAL' actions.
    By 'REAL' I mean, executing DB actions, writing files, stuff like that, as opposed to just sending HTML.

    When I hit the 'Back' button to my PHP page, Assuming it is a GET.

    • Does it mean my PHP code will not necessarily run all the time, on all browsers ?

    • If I have an image I would like to refresh every time I ask for that page (especially on 'Back'), how should I go about that?

    Is it just me or having an internal dislike for javascript is normal ? (It always seems to me like a patch for things that couldn't work in the first place, plus not everyone let javascript work)

    I am not picky but is it ok to think that a HTTP level solution would be the best here ?

    Thanks

    解决方案

    Pages that are loaded via POST will cause the browser to ask the user to resubmit the information to view the page resulting in the actions performed by that page happening again. If the pages is requested via GET and has variables in the querystring the same thing happens but silently (without the user being prompted to d it again).

    The best to work around this is to use the POST/REDIRECT/GET pattern. I used it in an example about processing payments that I wrote for Authorize.Net. Hopefully that points you in the right direction.

    这篇关于PHP和浏览器的“返回”按钮 - 真正发生了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆