dsqe46004 2012-06-15 08:14
浏览 84
已采纳

重定向时提供成功消息的最佳方法是什么?

I'm searching for the best way to supply the page after a redirect with a success messages. I think redirecting after a form was submitted is the best way to prevent a form to be submitted multiple times.

The following possibilites are some that I got in my mind. What do you think is the best of them and why or do you have other possibilities?

  • Save the message in the session and read from there on the target page
  • Supply the new page with some GET parameters like header('Location: index.php?success='.urlencode($message));
  • Supply more than the Location header and read them on the target page like this

    header('Location: index.php');
    header('X-Success-Message: ' . urlencode($message));
    
  • 写回答

2条回答 默认 最新

  • dongtui8593 2012-06-15 08:45
    关注

    This is my opinion:

    Session.

    All data that you ar storing in session will be stored on the server. The default location is disk. IO - is a very limited resource. Do not start sessions when you do not need to. Do not store data in sessions when you do not need to.

    Supply the new page with some GET parameters.

    It is a good practice, but has one lack. If the client stores links in his favorites (and etc...) gives it to another user and he opens this link later, then he will see the success message.

    Supply more than the Location header and read them on the target page.

    It is a good method, but it depends on the server configuration and proxies in the middle of application and client. Sometimes the server configuration (proxies) kill non standard headers. But usually it is not a problem.

    Store this data in cookies.

    Lacks:

    • Do not forget to delete cookies.
    • All data stored in cookies will be transferred from your server to client and back.

    Store this data on the server.

    Storing in database, memcache, NoSQL and etc. If this does not create additional load on the server and is ideally suited for your application, why not? And you need not necessarily to store the message itself, but only a state flag.

    In practice I use all this methods. Which method should be used at the moment - look at the requirements for the application and its future use.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?