Hi there,

this is code that worked for a form to form to form page (multiple form steps). I got it from the php.net site:

2003-04-24: source for this was on: http://www.php.net/manual/en/function.session-cache-limiter.php

session_cache_limiter('none');
session_start();
$expires = (function_exists('session_cache_expire') ? session_cache_expire() : 60 ) * 60;
$gm_expires = gmdate('D, d M Y H:i:s', time() + $expires);
header("Cache-control: private, max-age=$expires, pre-check=$expires"); 
header("Expires: $gm_expires GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

Boy I can assure you, when I put this at the head of the page, I NEVER get this message:

Warning: Page has Expired

But the problem is this:
Suppose I'm at page index.php?view=default, which lists about 25 records. I click and a "delete" icon I have to the left of that, and that goes to index.php?deleteID=22, which will delete record #22. OK, since index.php?view=default is different than ...?deleteID=22, this is a new page and you'll only see 24 records (we got rid of 22).

OK, now, if we either hit back in the browser, or click on an exact link index.php?view=default, I get 25 records. So far no problem, most people would instinctively hit Control-R (Refresh Page), and expect to see 24 records.

BUT... no go (at least in I.E. which is all I care about for this Intranet). You can hit Control-R till the cows come home, and you can't get the updated page from the database.

One of the things that's ALWAYS bothered me about PHP vs. ASP (really the only thing) is this Warning😛age has Expired feature.

Can anyone give me something that WORKS?

If this continues I'm going to have to snoop raw headers from ASP pages and figure this out. I can't have a functional site with these warnings, OR with this no-refresh problem.

Extremely grateful,
Sam Fullman
Compass Point Media

    7 months later

    I know your post is from over a year ago, BUT
    I was wondering if you managed to solve this
    session_cache_limiter() problem of 'total-caching' ?

    if so - I would love to get help with that..

    THANKS!

    Yanay.

      Well, the results aren't astounding, but I do have something I use to get around some of it.

      As you know, when you cache with PHP, you unfortunately cache too much; you either get a page the reloads every time you hit the back button, or a page that you CAN'T reload by hitting Control-R.

      The biggest problem I had was solved by this code following; that is, when in multi-step processes, where you post a form three times for three steps, and you want to go back, have to see that ugly "Page has expired". With this, if the page was created with a POST, you won't get that, AND I've found that control-R WILL break through a post page -- but it won't break through a _GET method page.

      Here is the code, and then a comment afterwards:

      if($_POST){
      	//we save this page so when we go back it is still there, AND it will be scrolled down to the same place
      	//if the user needs to and realizes that the data may have changed, he can hit Control-R to refresh
      	session_cache_limiter('none');
      	session_start();
      	$expires = (function_exists('session_cache_expire') ? session_cache_expire() : 60 ) * 60;
      	$gm_expires = gmdate('D, d M Y H:i:s', time() + $expires);
      	header("Cache-control: private, max-age=$expires, pre-check=$expires"); 
      	header("Expires: $gm_expires GMT");
      	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
      }else{
      	session_start();
      }
      
      

      NOTE: Yanay, the best thing I can think of, if you or someone wanted to try it, would be to find an .asp site (yuck I know) that behaves the way you like -- and I've seen them out there. Then write a script which spoofs a browser and gets the raw HTTP headers from each page through the process. Then study them and implement them in your code.

      This would take a good 2-5 days, and honestly I don't think anybody knows a solution on this or has put in that effort.

      If you ever do it to my satisfaction I'll gladly send you $50.00! But we're talking a very detailed report which you'd have to want to do for your benefit as well obviously at that price :-)

      HTH,
      Sam

        First - I really do appreciate the quick response..
        I don't see myself actually taking the week off - just to dive into
        ASP wonderlands, but I will try to figure out your code.

        you might as well want to take a look at a more primitive solution I have found on devshed.com:

        "You can send the session id with the form in a hidden field

        PHP:--------------------------------------------------------------------------------

        <input type="hidden" name="SID" value="<? echo session_id() ?>">

        "..

        don't ask me why/how... but it works!
        it vanishes the "page expired" page, and make a refresh possible!

        anyway - thanks... and I'll be happy to try & help if you need advice some day.. :-)

        yanay@explosite.com

          starting a major company based on PHP as I am, I will eventually have to figure this out to the hilt so that I can fine-tune performance. If you'd like to be on my mailing list so you remember this thread until then, pm me at sfullman (my ID).

          The phpsessid thing you mentioned is interesting and may provide a clue into another intermittent bug I've been getting.

          Thanks yanay!
          Sam

            Write a Reply...