Jump to content

possible cache problem


papaScott

Recommended Posts

Hello everyone,

I have a small php app that will inject data into a file, then allow the user to download the file.  the problem is that the file they download doesn't seem to be the most recent one. I've  checked the file on the server, and then i've downloaded the file using the app. It seems to be a cache issue, as the browser is holding the file in temp internet files for fast access.

 

what can i do to resovle this? Do i have any other options besides adding a time stamp in the file name, thus having the browser redownload the file.

 

Please help if you can.

thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/240003-possible-cache-problem/
Share on other sites

Assuming you are using a link to directly download the file you can add something meaningless to the URL that makes it different each time:

 

echo '<a href="http://www.example.com/downloads/file.txt?id=' . time() . '">';

 

Or if you have a PHP script that gets and then outputs the file contents for download, then you can add some no-cache and expire headers before the output. I don't remember for what browsers certain ones of these are necessary so I included all of them. Something like:

 

header('Expires: Sat, 01 Jan 2011 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Pragma: no-cache'); 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.