3

I have a page with an editable table. I need users to be able to edit this and then submit their changes. Everything works well until I redirect them to the same page with new content (relevant to their changes). However, they see the old content.

If I press ctrl+f5 on the browser, they content gets updated. I was wondering if there is a way to force this. This is my php code which does not help force refreshing:

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Pragma: no-cache');
header( 'Location: http://www.bamozir.com/en/mtl-en/recent/general-info/cost#edit' );

Eugen Rieck Solution works perfect for firefox, chrome, and safari. But not on IE and Opera. Any idea how to fix this?

Nasim
  • 105
  • 1
  • 2
  • 9

3 Answers3

3

What ALLWAYS works: Assuming your URL is http://my.server/my/page?a=b&c=d you redirect to http://my.server/my/page?a=b&c=d&nocache=1234567890 with 1234567890 being a large random number

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
  • http://www.bamozir.com/en/mtl-en/recent/general-info/cost#edit?nocache=1234567890 this didnt work – Nasim Dec 20 '11 at 15:38
  • The browser sees the request as a totally new request which hasen't been cached if you add some random value to the url. This way it will not use the cache. – rzetterberg Dec 20 '11 at 15:39
  • hashtag is for the anchor...it seems that it is working now. Thank you. – Nasim Dec 20 '11 at 15:43
  • this is what I finally used: http://www.bamozir.com/en/mtl-en/recent/general-info/cost?nocache=1234567890#edit – Nasim Dec 20 '11 at 15:52
2

You must set the cache control and expiration on the page which you wish to force-refresh on. By setting that before the redirect, you're telling the browser to not cache the page you're redirecting from.

Mattygabe
  • 1,772
  • 4
  • 23
  • 44
  • All of my pages is controlled the same way with the same header. I cannot change the php for this particular one. Is there a way that I can simulate ctrl+f5 only after users press submit on the modified data? – Nasim Dec 20 '11 at 15:33
2

Use this header to use refresh:

Refresh: 0;url=http://www.bamozir.com/en/mtl-en/recent/general-info/cost#edit

See more on that topic here: 'Refresh' HTTP header

Community
  • 1
  • 1
rzetterberg
  • 10,146
  • 4
  • 44
  • 54