1internet Posted January 5, 2013 Share Posted January 5, 2013 e.g. a member updates their details and are redirected to the homepage, index.php?message=updated. The page gets the variable $_GET['message'], and sees that it equals updated, which makes it display "You information has been updated" in the update div. Now whenever that page is refreshed or the visitor goes to it again, i.e. index.php?message=updated, then it will always display that message. Even if you use jquery for the message to timeout. What is the best practice for such messages, am I right to assume sessions are involved? Quote Link to comment https://forums.phpfreaks.com/topic/272740-marking-status-messages-go-away-on-refresh/ Share on other sites More sharing options...
Andy123 Posted January 5, 2013 Share Posted January 5, 2013 Why would someone navigate to that page again if their details have not been updated? You would not be linking to such a page. If they want to refresh for the fun of it, then that is their choice. Perhaps you have a good reason for wanting to prevent this from being possible, or it just may not be necessary to do anything about it? If that GET variable is only set to "updated" when their details have been updated and nowhere else, then I do not see the problem. Quote Link to comment https://forums.phpfreaks.com/topic/272740-marking-status-messages-go-away-on-refresh/#findComment-1403496 Share on other sites More sharing options...
1internet Posted January 6, 2013 Author Share Posted January 6, 2013 Yes, but what if they clicked on a link from the updated page, and then hit back again, it is still going to show the message, it's not professional. How can it be overcome? Quote Link to comment https://forums.phpfreaks.com/topic/272740-marking-status-messages-go-away-on-refresh/#findComment-1403500 Share on other sites More sharing options...
Andy123 Posted January 6, 2013 Share Posted January 6, 2013 (edited) Usually, this is done by having an HTML form with a method of POST. The action would be to the same page, and then the server would generate the message based on the submitted values (e.g. if no validation errors occur and a database query was successful) and not based on the URL. If the user navigates away and attempts to go back, then most, if not all, browsers will show a notification that to reload the page, the POST data has to be resent. This is a quite common approach. Edited January 6, 2013 by Andy123 Quote Link to comment https://forums.phpfreaks.com/topic/272740-marking-status-messages-go-away-on-refresh/#findComment-1403502 Share on other sites More sharing options...
haku Posted January 6, 2013 Share Posted January 6, 2013 The problem here is that you are setting the message to show using a variable in the URL, which essentially permalinks the value into the URL. You should be passing the message in some other way - a cookie or a session is probably your best bet. Once the message has been loaded, you can then clear the cookie/session and the message will not be shown the next time. The URL will be the same whether the message is shown or not, so you won't see the message more than once, with the exception of when the user navigates to the page when it is still in memory (ie the back button). Quote Link to comment https://forums.phpfreaks.com/topic/272740-marking-status-messages-go-away-on-refresh/#findComment-1403565 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.