Jump to content

marking status messages go away on refresh


1internet

Recommended Posts

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?

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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 by Andy123
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.