How to display messages to the user after a POST + HTTP redirect
error-handling, post-redirect-get, redirect, session, user-interface
Solution
Pretty much every website that allows users to log in does so by relying on a cookie. It ain't a perfect solution, but it's the best we got.
Also session handling is one of those things that a web development framework typically takes care of for you.
Problem
I’m using the PRG pattern to avoid multiple form submission. It has, however, a serious drawback — you cannot simply `echo` the confirmation message to the user (obviously, the user won’t see the page, he will be redirected to another one). What are the solutions to this problem? I know two of them, but none of them seems perfect. - Use a custom redirect URL, like: `http://example.com/?msg=data-saved`. It’s stateless, so I think it’s quite reliable. But it creates problems when user copies the link, bookmarks it, etc. - Store a session variable/cookie, and check it on every page load. If it’s set, clear it and display the message. It seems OK, but I’m not sure about this one — it relies strongly on cookies, it’s a little more complicated. Or maybe there are other ways I don’t know about? Some combination of sessions and URL parameters? I don't know. What’s the best way in your opinion? Which one has the least drawbacks? What are the pros and cons?