Manual refresh loads older version site - php

So I am making a small web app using php. I'm just inserting into a MYSQL hosted at eHost. http://www.gearedwebdesigns.com/BPHCalcEnter.php
I have zero problems on desktop with caching. Different story on my android Galaxy s7 in Chrome. If I use the chrome inspector and remote devices then I can see the latest php update by doing CTRL+Shift+F5. However, if I refresh by pulling down then it loads an older version. I have tried clearing cache multiple times.
I've added this to my .htaccess
<filesMatch "\.(html|htm|js|php|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
And I have this at the top of my php file.
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
Any ideas? Thanks.

Related

How to override htaccees file for cache control header

In my company we have htaccess file in which there is no web caching enabled,I want to enable caching for one single api but htaccess file is overriding my cache control that I am setting via header function.Can someone help me please?
htaccess file
<ifModule mod_headers.c>
#BEGIN Security Headers
Header set X-XSS-Protection "1; mode=block"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-Content-Type-Options "nosniff"
#END Security Headers
# BEGIN Cache-Control Headers
#To disable ETags
Header unset ETag
<filesMatch "\.(ico|jpe?g|png|gif|swf|woff)$">
Header set Cache-Control "max-age=86400, public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, no-store, no-cache, must-revalidate, max-age=0"
Header set Pragma "no-cache"
</filesMatch>
# END Cache-Control Headers
my api php file
header("Pragma: cache");
header("Cache-Control: max-age=300");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 300) . " GMT");
header('Last-Modified: ' . gmdate("D, d M Y H:i:s", time()) . ' GMT');
header('Content-Type: application/json');
response
There is a property setifempty in apache which works for version>2.2,but for me it was 2.2 so I replaced setifempty with below command
Header append Cache-Control ""
Header edit Cache-Control "^$" "private, no-store, no-cache, must-revalidate, max-age=0"
Header append Pragma ""
Header edit Pragma "^$" "no-cache"
The above code was edited and it has worked out for me

can't cache static files using htaccess

I am new to caching and i am trying to test how files would be cached so i have created a simple php web page to test if i can cache the css file:
<!doctype html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1 id="heading">Test</h1>
</body>
</html>
and i have created an htaccess file then added these lines from here
# ----------------------------------------------------------------------
# | Expires headers |
# ----------------------------------------------------------------------
# Serve resources with far-future expires headers.
#
# (!) If you don't control versioning with filename-based
# cache busting, you should consider lowering the cache times
# to something like one week.
#
# https://httpd.apache.org/docs/current/mod/mod_expires.html
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
</IfModule>
then i tried to change style to check if it is cached but style changes on every load which means that there is no caching, then i thought my be it is the local server configurations so i moved to live one and agian still the same and it tested headers with this site
and i got this:
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Sun, 24 Sep 2017 13:02:51 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: max-age=0
Expires: Sun, 24 Sep 2017 13:02:51 GMT
Vary: Accept-Encoding,User-Agent
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
EDIT:
I have found that mode_expires was not active on localhost and i enabled it but still facing the problem
try adding this part :
<IfModule mod_headers.c>
<FilesMatch "\.(ico|jpe?g|png|gif|swf|css|gz)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\.(js)$">
Header set Cache-Control "max-age=2592000, private"
</FilesMatch>
<filesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
# Disable caching for scripts and other dynamic files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</IfModule>

Clear cache of index page in drupal

I have tried the code below to clear the cache of the index page to show the latest content to the user.
<filesMatch "index.html">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>
But when I try this code it gives forbidden error.

I'm not able to cache my PHP rewritten CSS file

I have a php file that is renamed in htaccess as a css file. The reason being, is because I have some styles and colors which change based on some admin options.
Anyway, I am trying to allow a visitor's browser to cache the file. Here's what I have:
style.php:
header("Content-type: text/css; charset: UTF-8");
// Start normal CSS styles...
.htaccess:
RewriteRule ^assets/css/min/([a-zA-Z0-9\._-]+)/([a-zA-Z0-9\._-]+)/([a-zA-Z0-9\._-]+)\.css$ assets/css/min.php?style=$1&layout=$2&ver=$3 [L,QSA]
# Compress
AddOutputFilterByType DEFLATE text/css
# Cache for 1 week
<FilesMatch ".(css)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType text/css "access plus 1 week"
</IfModule>
In the page head:
<link rel="stylesheet" href="http://example.com/assets/css/min/blue/flat/0.9.2.css">
Each time a new page is loaded, the page contents are requested. These are the headers I receive:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 13881
Content-Type: text/css; charset: UTF-8;charset=UTF-8
Date: Sat, 20 Feb 2016 22:49:17 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=5, max=94
Pragma: no-cache
Server: Apache/2.4.16 (Unix) OpenSSL/1.0.1p PHP/5.6.12 mod_perl/2.0.8-dev Perl/v5.16.3
Vary: Accept-Encoding,User-Agent
X-Powered-By: PHP/5.6.12
Your mod_expires config applies to files based on their mimetype as perceived by the webserver. Unless you've done some major surgery on the webserver config elsewhere, the webserver will not associate the text/CSS mimetype with files ending in .php (and if it did, much further hacking would be required to get them processed by the PHP parser). The header set by your PHP script is irrelevant to this process.
While it is possible to force mod_expires to add caching headers to the response, you'll also have to use mod_headers to remove the values PHP sets; when a browsers receives multiple conflicting caching instructions, it will resort to the shortest expiry time expressed in them.
Hence, to make the content cacheable, you should emit the caching information directly from the PHP script. E.g.
header('Cache-control: max-age=604800; private');
But basing the expiry time on the access time is not the best solution.

How to disable caching 100% [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Cache Control fails
I am currently using:
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
and
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="-1">
<meta http-equiv="pragma" content="no-cache">
Yet it still caches
You can also add Pragma: no-cache. And make sure Last-Modified is far enough in the past: some small clock skews between the client and the server could trick your client into thinking it has a fresh version of the document; use Tue, 15 Nov 1994 12:45:26 GMT for example. And also add an Expires header with date in the past.
I normally add this in my .htaccess
<filesMatch "\.(js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>
Modify the fileMatch to add other extentions ...
Add timestamp to the end of each URI, and the browser won't retrieve it from cache (as it will be with another URI on the next load)

Categories