PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old December 22nd, 2002, 11:43 AM
wap wap is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 20 wap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Browser Cache with php

My index.php page contains latest news taken from a MySql database. The problem I get is as some browsers save the last visited page view, when visitors return any news added doesn't show unless they refresh the page. What is the best way to overcome this problem so a manual refresh is not needed.

Thanks and hope someone can help.

Reply With Quote
  #2  
Old December 22nd, 2002, 01:51 PM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
You need to tell browsers not to cache your data with the following http headers

PHP Code:
 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
                                                     
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0"false);
header("Pragma: no-cache");                          // HTTP/1.0 


(from www.php.net/header)

HTH,

Hadley

Reply With Quote
  #3  
Old December 24th, 2002, 06:01 AM
invoke invoke is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 6 invoke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
if hadley's example does not work try this:
PHP Code:
 header ("Expires: ".gmdate("D, d M Y H:i:s"time())." GMT"); 
header ("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
header ("Cache-Control: no-cache, must-revalidate"); 
header ("Pragma: no-cache"); 


I had all sorts of problems trying to get no-cache to work until I set both expires and last-modified with getdate().

Reply With Quote
  #4  
Old December 24th, 2002, 09:34 AM
wap wap is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 20 wap User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your help guys. I actually cheated a bit and viewed the source code of these forums home page and a solution was there staring me in the face.

<!-- no cache headers -->
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="no-cache">
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
<!-- end no cache headers -->

Very similar to your suggestions and I will in fact try them both and add them to my script reference library i am building for personal reference.

Again thanks.

Reply With Quote
  #5  
Old December 24th, 2002, 04:18 PM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
It's slightly better to send the no-cache http headers (using the header function) because any proxies along the way will also heed your suggestions. Most proxy caches don't actually parse the html so won't see the http-equiv metadata.

In any case, you only need one or the other, not both.

Hadley

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Browser Cache with php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway