I've moved a older site to a new server, and the client has found a very odd behaviour.
Very close to the end, I have this code:
if (!$this->cache) {
header('Expires: '.gmdate('d M Y H:i:s', 946684800).' GMT');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
}
Now the odd thing is the Cache-Control line doesnt work.
After packet sniffing I see this:
Expires: 01 Jan 2000 00:00:00 GMT
Cache-Control: max-age=300, public
Pragma: no-cache
The order of the headers is exactly how I set them, but the Cache-Control is completely different. I've grepped my code for any mention of cache-control and there is only that mention, and another one designed to force caching in a different file but it is a different line to what I'm seeing so it cant be the culprit.
Does anyone know why Cache-Control is changing?
If you are using sessions, it's possible that PHP is overwriting them. Take a look at session_cache_limiter() in the manual.
Alternatively, you can try setting those headers after you call session_start().
(Edit: I missed the bit about "Very close to the end," so maybe this isn't your problem.)
I think you are running Squid, you should check its config for:
header_replace Cache-Control max-age=300, public
Related
I'm still inexperienced as a web developer so I have exhausted my knowledge on my current problem.
I recently made changes to files on my one website and uploaded them via FTP to the server. When I go to the website it's still executing the old code.
I cleared all my cache and tried on different devices. Even after changing the file names for example "logout.php" to "logout_code.php" as well as link references to those names when I click on the logout button it still goes to "logout.php".
Can anybody shed some light?
Try setting a no-cache header on the page that redirects to the logout page.
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
The above snippet goes at the top of the page before any other output is sent. (within a <?php ?> tag of course)
I crete a web service in php and which returns JSON. It works fine but it seems to be cache results I changed values in the table and the service doesn't reflect this change. I included the following code but it doesn't seem to work. in my browser I am still getting the old values. How can this be rectified?
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
You may want to check your Ajax library (client) documentation see if you can disable its caching mechanism.
If you wish to disable cache on server side, refer to "How to control web page caching, across all browsers?"
Really stumped on this one.
I'm trying to cache some resources with the HTML5 cache manifest (yes, I know, don't judge me), but the manifest seems to be caching itself.
The manifest file is actually a dynamic PHP script, so it has a .php extension.
The following headers are set (How do I completely disable caching in Cakephp?)
header('Cache-Control: no-store, private, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false); // HTTP/1.1
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Expires: 0', false);
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Pragma: no-cache');
header("Content-type: text/cache-manifest");
The manifest contains the following in the NETWORK section:
NETWORK:
/cachemanifest
/cachemanifest/
/cachemanifest/*
*/cachemanifest/*
cachemanifest/
cachemanifest
/cachemanifest/manifest.php
cachemanifest/manifest.php
*
Of course, the manifest file itself is excluded from the CACHE: section.
There's also a .htaccess file in the same directory containing this:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>
The site is built with CakePHP, which apparently has some 'helpful' caching mechanisms that I don't know much about. I'd assume the PHP headers would bypass anything... PHP could do.
So, what am I missing?
Actually, it looks like one of these worked. It just takes 30+ seconds for the cache to realize that it needs to update.
The way cache manifests work is that for the manifest to update itself some text inside the manifest has to change, even if it's just one letter. This can be done by having a build automator add a timestamp every time there is a change in code.
I have a .htaccess in my root directory with the following setting.
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=864000, public, must-revalidate"
</filesMatch>
I thought it caches any of the files in the filesmatch directive. One thing that I am not clear about is whether the browsers cache the actual HTML content that goes out (from index.php) or not. I don't want browsers to cache the HTML. I only want browsers to cache the images, css and js.
Thank you.
From what you are saying you are uncertain if the browser is caching your PHP file or what is generated from it, use these headers to be absolutely certain, you will never know unless you are explicitly setting rules for it:
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
When using Codeigniter or a simple php page, loadin my test page once I get the normal 200 status but if it is cached I get the 304 message. I realize this is just a signal that the resource is cached but could I avoid it?
If so, how?
Thank you.
... or you could just do
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
in your PHP files right at the top. That way you have control over which pages not to cache and leave Apache running as it should.
If you don't want the page to be cached by browsers you need to configure the apache server to send the appropriate headers.