Server picking up old files - php

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)

Related

Turn off caching of web service response

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?"

Image loaded 3 times by firefox when using curl & php

When i'm loading an image by curl through PHP but when opening it in firefox it shows me thet the image is loaded 3 times by checking for caching or something.
I'm using tamper-data and I saw this problem shown below.
I've tried using header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); but no solution.
Also by using random get data to force image download and no caching still not working.

Cache Manifest Caching Itself

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.

how we can delete cache forcefully when user logs-in using javascript

Can anybody tell me how we can delete browser cache using javascript. I want this because I am giving user, file for download with url ('http://www.example.com/docs/doc1.xlsx'). and this files are accessible for that specific user only.
I am checking with htaccess redirect to other action which redirect to that specific file url if user does not have access then Access Denied page come.
But problem is when valid user download that file and logs out from application and copied above url and hit enter on browser file gets for download without accessing to server, which happens due to caching in browser.
So I want to delete cache when user logs out of system.
Alternative solutions are most welcome.
In short, you can't (or, at least, I have never seen a way of doing it).
You'll need to do it on the server side by sending the correct cache-busting headers. Something like:
Cache-Control: no-cache, must-revalidate, max-age=0
You can do this using (to steal an example from the PHP documentation):
header("Cache-Control: no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
This is not possible. Php only works serverside and using javascript is not working because of security issues. ActiveX is not an option eigther i guess.
What you can do is to attach a no-cache header for a page that must reload each time.
Rather than giving direct access to the file (as you mentioned "http://www.example.com/docs/doc1.xlsx"), I think you should read the the file in php and give it for download after checking for the valid user..
Example taken from php.net
<?php
// downloading a file
$filename = $_GET['path'];
/**
* YOU CAN CHECK YOUR VALIDATIONS HERE..
*
*
*
*/
// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=".basename($filename).";");
/*
The Content-transfer-encoding header should be binary, since the file will be read
directly from the disk and the raw bytes passed to the downloading computer.
The Content-length header is useful to set for downloads. The browser will be able to
show a progress meter as a file downloads. The content-lenght can be determines by
filesize function returns the size of a file.
*/
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
#readfile($filename);
exit(0);
?>
Hope this helps..
Thanks...
I have resolved issue without major modifications.
Firstly I tried by setting header as you people suggested. Before redirecting for file to download I tried to set header for cache-control, but it doesn't work at all.
So I stretch my mind more and find simple solution by setting headers in .htaccess file which is located in folder where all downloadable files are located. That means cache-control header is set to download files response.
But still one thing in mind why above solutions not working.
And one more thing Pragma: "no-cache" not working for IE. that is it gives error while downloading requested file as "requested site is unavailable or cannot be found".
So I have set it to Pragma: public. But I doubt whether it is secure.

Edit file download info PHP/JS

Hey, I'm trying to change the name of a file being downloaded through my site off an external server.
Currently whenever I modify the header information, it just takes a reallllllyyyyyy long time for the download to start, so is there any way to do it without changing the headers? Or if not any reason why it would be taking forever to load with my headers?
This is what I'm doing
#header("Cache-Control: no-cache, must-revalidate");
#header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
#header("Content-Length: ".getfilesize($url));
#header("Content-Disposition: attachment; filename=".$name);
#header("Content-type: audio/mpeg;\r\n");
die(#readfile($url));
Could it be done in javascript or something instead? And could i make it so all downloads start without opening in like windows media player, quicktime etc.
Thanks :)
It takes a "reallllllyyyyyy long time" because your loading the file to your server first and then send it to the client everytime someone is clicking the download link.

Categories