Documented research indicates that on Fri, 27 Aug 2004 15:20:58 -0600,
Michael Gale wrote about "[PHP] Browser back button":

>Hello,
>
>       I am sure this has been asked more then a few times but ... I have a web site 
> where almost every page is dynamically
>created. So if at some point in the site if you hit your browsers back button a popup 
>window occurs and asks if you want
>to resubmit the data. Upon clicking yes the page is properly displayed.
>
>That is a pain in the a$$ and I get many user complaints -- so far I have thought 
>about saving the requested URL and
>query string in a session variable and loading a back button on every page.
>
>This seems to work create if the previous page can be loaded using a GET request but 
>if the previous page was loaded
>using a HTTP POST it seems I an up the creek with out a paddle :(
>
>Any one have any ideas ... 

The way I do it is urlencode the query string and then store it with a 32
character cut of a md5'ed version of the query + timestamp in the database,
then the MD5 version is used to create GET urls back and force and to
back-reference to the actual page itself to allowed for changing sort orders
on tables and such...

the links to the pages then look like
<a href="page.php?query=a4545f454dg454">link</a>

the script-pages then have a simple if-structure:

if (isset($_GET['query'])) {
   // load $_GET['query'] from the database and urldecode it
} elseif (isset($_POST['submitted'])) {
   // do whatever you do when form is submitted
} else {
   // dummy default to handle page load without submitted data
}

it's admittedly a little clumsy, but it was the most efficient way I could
find that allowed to store queries and pull them out later, and do it in a
way that prevented loading the URL with a get string that's too long to work
... the reason I add the timestamp is simply to prevent similar codes when
cutting them down ... sofar I've not had any problems with this...

all there is to remember is to add the right code to the links, for whether
uou're going backwards or forwards, or referencing the page itself.... I use
this method with great success on pages that have user-changable sort order
and and sub-queries on the fly ... 

probably a prettier way to do it, but it gets the job done...

oh, and I save a timestamp with the query, then clean them out as they pass
7 days of age ... that way it's also possible to link directly to a query,
and it prevents the database from overload on past queries...


Rene
-- 
Rene Brehmer
aka Metalbunny

If your life was a dream, would you wake up from a nightmare, dripping of sweat, 
hoping it was over? Or would you wake up happy and pleased, ready to take on the day 
with a smile?

http://metalbunny.net/
References, tools, and other useful stuff...
Check out the new Metalbunny forums at http://forums.metalbunny.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to