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
Share on other sites

Try adding these in the <head></head> section of your app to prevent browser from caching.

<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0"> 

Link to comment
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'); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.