SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sessions and cache issue

    To enable the use of the back button in combination with sessions, I added the following line to the top of my pages:

    ini_set("session.cache_limiter","public");

    This works well, but now I have the problem that when someone clicks on a link they see the 'old' cached page which doesn't reflect the latest changes.

    What I would like is the following:

    -When people use the back button they should see the cached page

    -When they click on a link they should see the "non-cached" page which reflects the latest changes.

    How can I accomplish this?

  2. #2
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to send a no-cache header, here is a sample of one.

    PHP Code:
      header("Expires: Mon, 14 Jul 1996 05:00:00 GMT"); 
      
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . "GMT");
      
    header("Cache-Control: no-cache, must-revalidate");   
      
    header("Pragma: no-cache"); 
    This basically tells the browser to dump the page because its too old and make a new one from scratch.

    I hope that helps.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  3. #3
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I don't cache the page then the back button won't work, so the nocache headers would not help here.

    When I use sessions my pages are not cached by default.
    That's why i used : ini_set("session.cache_limiter","public");

    Now the pages are being cached and the back and forward button works, but I need the browser to show the 'newest' pages instead of the cached ones.

    How can I enable the use of the back and forward buttons in combination with sessions and have the browser display the most recent changes when people click on a link?

    I hope I'm clear enough

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can trick the browser into not caching the links when people click on them by tacking on a unix timestamp on the end of the link, this way the browser thinks its a new page and you will fool the cache into thinking that way too.

    <a href="somelink.php?somevar=someval&ck=<?=time()?>">go there</a>

    I use ck it stands for cache killer, but you can use whatever as long as it doesn't conflict with some other var you may be using. I hope that helps.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddy is right, you could try that.

    my version was only to have ti clean out the cache to fetch a page, but it does eat the users bandwith trying to reload every page.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  6. #6
    SitePoint Addict jamesbond's Avatar
    Join Date
    Feb 2001
    Location
    The Netherlands
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried Freddy's suggestion and it works!

    Freddy and Theiggsta, thank you for your help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •