Session Cache

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

If a user has missed something when they preview a form I want to
return them with the back button or the cancel button to the previous
page. Msie gives me the page expired error and firefox gives me a
button to reload. But then of course all the entered information is

Pages are
page1 (the form)
page 2 (preview page)
page 3 (confirmation page)

I googled around and found this


With that at the top of each page it works but then I realised that it
might be a good thing to restict the length of time they can do this.

I googled on found something else so now I have put 3 lines of code at
the start of each page.

session_cache_expire (1);

But the user can still go back and forth even after the one minute

As usual I need help with the syntax, how to I flash up the page
expired error if a user clicks back say in 15-20 minutes?

Any help, greatly appreciated...

Garry Jones

Re: Session Cache

El 09/09/2010 5:24, GarryJones escribió/wrote:
Quoted text here. Click to load it

How do you want to recover previous form values? Saving them into a
session variable or leveraging the browser cache? You are mixing
directives for both purposes.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Re: Session Cache

Quoted text here. Click to load it

Out of my depth as usual....

What I want...

The user fills in the form input textboxes, clicks textboxes and
submits form for preview.
The user sees he has misspelt something or forgotten to tick a box.

He clicks back on the browser. If he does this within say 5 minutes
then he will return to the form in its previous state, all text and
boxes will still be entered and status held for checkboxes. (I have
got this working). The user can also click cancel on the form instead
of ok, For that I use <input type="button" value="Cancel"

The way I got this working was to put
session_cache_limiter(private_no_expire); before the session_start()

If he has waited more than 5 minutes then "page has expired" will be
displayed in msie.  (Resend or something in firefox). In both msie &
firefox the keyed in data is gone and he will have to start again. I
don't care about macintosh, google crome, safari or iphone. If people
use those products that can expect to have to key in the entire data
again. I don't need to overwork this little problem. Msie v7+ and
Firefox 2.6+ catches 99% of my users.

For the timeout I tried
session_cache_expire (1);

But that didn't work.

So how do I "add" a timeout to
session_cache_limiter(private_no_expire) ?
no_expire makes me feel that a timeout can not be added. In that case
what do I put in to get what I want, ability to use back and cancel
for 5 minutes.

Garry Jones

Re: Session Cache

El 09/09/2010 13:57, GarryJones escribió/wrote:
Quoted text here. Click to load it

Sorry if I didn't explain myself correctly. I think it's pretty clear
*what* you want to accomplish. But you don't even mention *how* you want
to do it.

Unless I misread your messages, you are not asking for generic ideas
about how it can be done in PHP. You mention some random PHP functions
you are using, you explain that "it didn't work" and you ask some
extremely specific questions that are difficult to put in context.

Quoted text here. Click to load it

You cannot add a timeout to an HTTP header. The whole idea does not make
any sense... Given that you "quote" it, I presume it's not a literal

I'll start guessing:

You want to instruct the browser to keep an HTML document in cache for
certain amount of time (but not more).

In that case, you need to generate the following HTTP headers:


$minutes = 5;

header('Expires: ' . gmdate('D, d M Y H:i:s', time()+60*$minutes) . ' GMT');
header('Cache-Control: max-age=' . 60*$minutes . ', s-maxage=' .
60*$minutes . ', must-revalidate, proxy-revalidate');

session_cache_limiter(FALSE); // Disable cache headers by session_start()

if( session_id() ){
    // session_start() has already generated a "Pragma: no-cache" header
    if( function_exists('header_remove') ){


I haven't tested with POST forms but it should possibly work.

Of course, it's up to the browser whether to obey or discard these
rules. If you want a stronger server-side control, you'd need to send a
new form each time (with previous values pre-filled).

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Re: Session Cache

GarryJones wrote:
Quoted text here. Click to load it

Using the browsers back button to "backspace" to a previous page in, as you
have, a multi page form is at best fragile. It's totally up to the browser
what happens when you press it's back button. It might refresh the page from
the server. It might display the page exactly as it was last displayed. It
might display it as it was last downloaded. None of this is under your

Every multi page form I have ever come across never even suggests that I use
the browsers back button. They all have two quite clearly marked submit
buttons at the bottom usually labeled [next] and [previous]. Sometimes the
previous button is also annotated with prose that sort of says if you don't
like what you see (on this preview page) then press me to "go back" to the
actual entry page.

This is, however, not a "back" button. It is a "go forward" to the page you
were on last. It might be implemented via a redirect status code so the
browsers history is sort of continuous bit it does *not* use the browsers
history, as the browsers back button does. It is all done server side, where
you *do* have total control over what you present to your user.

Do not rely on the browsers back button.

Re: Session Cache


Quoted text here. Click to load it

The usual way is to do 1) and 2) on the same page, i.e. submit the form
to itself. This makes it very easy to validate the input and simply show
the form again if something's wrong and missing, together with some
error message. Then the user can directly fix the mistakes and submit
again. If all is fine, the form script processes the data and shows the
confirmation page or redirects to one.

Quoted text here. Click to load it

This has _nothing_ to do with your form problem.


Re: Session Cache

On 9/9/2010 5:24 AM, GarryJones wrote:
Quoted text here. Click to load it

You might first want to read this before starting to approach this all
the wrong way:

No need to mess around with session settings if you set up your logic
the right way. ;-)

Erwin Moller

"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Re: Session Cache

On Sep 10, 12:45=A0pm, Erwin Moller
Quoted text here. Click to load it

Hi ,

We at [RNTLABS Software Solutions] have exciting
openings for the below

1/ PHP
2/ Designers
3/ Android
4/ iPhone
5/ QA
6/ ROR

Please apply at ASAP .


Piyush Gupta

Site Timeline