Back Button
am 17.11.2006 09:36:03 von Mike Scholl
I have written my first bit of php/sql code and set up a website with a
small database.
I use a html form and submit button to add/edit etc data.
If you are editing data, after you have updated the database, if the user
presses the back button repeatedly they scroll back through the previous
screens which show the data BEFORE the update.
I note on some site you get a "this page has expired" message if you try to
scroll back.
How can I do that? Or in some other way prevent outdated data from being
displayed.
Mike
Re: Back Button
am 17.11.2006 10:36:16 von Erwin Moller
Mike Scholl wrote:
> I have written my first bit of php/sql code and set up a website with a
> small database.
>
> I use a html form and submit button to add/edit etc data.
>
> If you are editing data, after you have updated the database, if the user
> presses the back button repeatedly they scroll back through the previous
> screens which show the data BEFORE the update.
>
> I note on some site you get a "this page has expired" message if you try
> to scroll back.
>
> How can I do that? Or in some other way prevent outdated data from being
> displayed.
>
> Mike
Hi Mike,
That is a browserthing. Good browsers respect some headers that come with a
document that say when a document expires. Caching influences this
behaviour too.
Here is a article:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Read at least from point 14.9 (cache control) and 14.21 (expiration).
And above all: TEST on a few browsers you want to support.
If you stick to the RFC, you did what you could to get the desired
behaviour, but be aware that the browser you use can be buggy (like some
versions of IE) and you need to circumvent that by adding more headers.
Regards,
Erwin Moller
Re: Back Button
am 17.11.2006 14:26:43 von Kimmo Laine
"Mike Scholl" wrote in message
news:n6KdnSHR3vQX6cDYnZ2dnUVZ8tSdnZ2d@bt.com...
>I have written my first bit of php/sql code and set up a website with a
>small database.
>
> I use a html form and submit button to add/edit etc data.
>
> If you are editing data, after you have updated the database, if the user
> presses the back button repeatedly they scroll back through the previous
> screens which show the data BEFORE the update.
>
> I note on some site you get a "this page has expired" message if you try
> to scroll back.
>
> How can I do that? Or in some other way prevent outdated data from being
> displayed.
If you use FORMs, when the form method is POST, you'll get the
expired-notification, but when the method is GET, it will not appear. This
is logical, since get should be used when searching for data, the list needs
to be generated just once, and you can go back to it again, but when
updating or inserting something, POST should be used for posting the data
just once, re-submitting should be rejected, or at least the browser should
issue a warning. Well, most browsers work this way, the magic is the form
method, weather it's POST or GET....
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)
Re: Back Button
am 17.11.2006 14:39:07 von John Dunlop
Mike Scholl:
> I note on some site you get a "this page has expired" message if you try to
> scroll back.
Well, you don't get the message from the server but from your
browser. The reason for it is that some browsers try to re-request
resources accessed through the history list, including POST requests;
and since POST requests are, more often than not, uncacheable, the
browser warns its user about a potentially unsafe interaction.
However, history lists are 'meant to show exactly what the user saw
at the time when the resource was retrieved' (RFC2616 : 13.13); in
other words, going Back is not meant to result in a new request.
http://www.ietf.org/rfc/rfc2616.txt
> How can I do that?
Read up on what cache directives the browser du jour wants.
> Or in some other way prevent outdated data from being displayed.
This is what the history list is _for_. Thankfully, you can't turn
it off.
--
Jock
Re: Back Button
am 17.11.2006 17:42:22 von Mike Scholl
Thanks for the suggestions. looks like I need to do a bit more studying but
I think I can see more or less how to do it
Mike
Re: Back button
am 14.09.2007 15:57:09 von Tyno Gendo
Albert Ahtenberg wrote:
> Hello,
>
> I have two questions.
>
> 1. When the user presses the back button and returns to a form he filled
> the form is reseted. How do I leave there the values he inserted?
I always capture the values into a session and when the form is created
I echo the session values into the value="" section, or whatever is
needed, different in the case of checkboxes etc., have to mark as
selected="selected" etc.
You could use normal cookies too if you don't want to start a server
session.
> 2. When the user comes back to a page where he had a submitted POST data
> the browser keeps telling that the data has expired and asks if repost. How
> to avoid that? I tried registering all POST and GET vars as SESSION vars but
> it also has its disadvantages...
I usually use a header redirect back to forms when data is invalid or
when a succesful submission is made, I use a session var 'messages' to
hold any messages to print at the top of the form
eg.
$_SESSION['messages'] = 'Your submission was invalid';
exit(header("Location: {$_SERVER['PHP_SELF'}"));