How to clear browser cache with php?
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Content-Type: application/xml; charset=utf-8");
can we forcibly clear browser cache through some code
Firstly, this depends on how long you've sent the expires
header for -- a day? Week? Month?
No matter when you've set the expires header, you have to wait until that time is up before the browser even begins to contact the server for a new version. So you will have to change the url as others have pointed out.
However, there is another good option for you, for the future...
If you set 'cache-control: "no-cache, must-revalidate"'
and a short Expires time, then the browser will check with the server every time it wants to re-display a cached object, using an "If-Modified-Since"
request header to send the last timestamp that your server originally sent with that cached object in its "Last-Modified" response header. If the object has been updated since the timestamp sent by the client, then the server will send the new object and a new Last-Modified
timestamp header. If not, it will respond with only a "304-Not Modified" response header.
So, the advantage of revalidation is that you still save some bandwidth with little risk of the client showing "stale" objects, but the disadvantage is that the client must wait while your server checks the client's If-Modified-Since header against the file's "Last-Modified" timestamp and of course, the server has to actually go check the filesystem to get that "Last-Modified" time. So all that's saved is the actual content transfer bandwidth and transfer time.
Good reading resources:
- http://www.mnot.net/cache_docs/
- http://code.google.com/speed/page-speed/docs/caching.html
Related Topics
How to Store File Name in Database, With Other Info While Uploading Image to Server Using PHP
How to Best Store User Information and User Login and Password
PHP - Redirect and Send Data Via Post
How to Know Which 'PHP.Ini' File Is Used
How to Best Configure PHP to Handle a Utf-8 Website
How to Insert an Item At the Beginning of an Array in PHP
Convert PHP Date to MySQL Format
How to Group a Multidimensional Array by a Particular Subarray Value
Group Array by Subarray Values
Remove All Elements from Array That Do Not Start With a Certain String
How Safe Are Pdo Prepared Statements
Any Way to Return PHP 'Json_Encode' With Encode Utf-8 and Not Unicode
Cannot Modify Header Information - Headers Already Sent By... Wordpress Issue
How to Get Enum Possible Values in a MySQL Database
Laravel Update Model With Unique Validation Rule For Attribute
How to Get JavaScript Function Data into a PHP Variable
Merging Arrays With the Same Keys
Why Does the PHP Json_Encode Function Convert Utf-8 Strings to Hexadecimal Entities