Jump to content


Photo

marking status messages go away on refresh


  • Please log in to reply
4 replies to this topic

#1 1internet

1internet

    Advanced Member

  • Members
  • PipPipPip
  • 137 posts

Posted 05 January 2013 - 06:25 PM

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?

#2 Andy123

Andy123

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationDenmark

Posted 05 January 2013 - 06:30 PM

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. :)
Blogging about PHP and other programming related subjects at CodingExplained.com.

#3 1internet

1internet

    Advanced Member

  • Members
  • PipPipPip
  • 137 posts

Posted 05 January 2013 - 07:14 PM

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?

#4 Andy123

Andy123

    Advanced Member

  • Members
  • PipPipPip
  • 134 posts
  • LocationDenmark

Posted 05 January 2013 - 07:30 PM

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, 05 January 2013 - 07:31 PM.

Blogging about PHP and other programming related subjects at CodingExplained.com.

#5 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,177 posts

Posted 06 January 2013 - 01:05 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com