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.
Related
I am working with scanning images.
Today I made a step forward but I think that I need something more in the header maybe?
Currently a scan request is POSTed to app running on Apache server and PHP 7.0. I receive that post and today I figured out I needed to reply with a custom 201 header.
I have the following custom headers set in PHP
header('HTTP/1.1 201', Created);
header('Location: /eSCL/Scans');
header('Cache-Control: no-cache, no-store, must-revalidate');
After doing I was able to see that a request is now made for an image, from the app to Apache server to /eSCL/Scans/NextDocument. "NextDocument" is actually a softlink to a .jpg, (but may also later be a PDF). The app GETs this file, I can also see that the server replies with the JPG file . That image should display in the scan app that made the request, but never does.
I think however I need something in the header to tell it it is a JPG , especially given it loads from a softlink with no extension . I tried the following with the same result
header('HTTP/1.1 201', Created);
header('Content-type:image/jpeg');
header('Location: /eSCL/Scans');
header('Cache-Control: no-cache, no-store, must-revalidate');
There must be a magic soup that causes the image to display in the app.I have tried both VueScan and Mopria android app with the same results
Thanks for any ideas in advance
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)
On Windows, the "fmp://server_address/database_name" protocol works fine in any browser, IE included.
But when I try to execute it from with a PHP script, it works on every browser except IE:
$url = 'fmp://99.99.99.99/Database_Name';
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-type: text/html");
header("Location: $url");
IE just gives a "webpage cannot be displayed; some content or files on this webpage require a program that you don't have installed". Similar to what you'd expect if the fmp protocol wasn't in the registry, which it is, because the FileMaker installer put it there, and the fmp:// protocol does work fine if you type it into IE's address bar.
Any suggestions how to launch it from a PHP script for IE users?
I am not a web developer by all means. But I am trying to help someone deliver a video from their server. Basically when the user clicks a button on the website, we want the user to be prompted to download the video. So after Googling for a while I figured out how to write a short php script using content-disposition:
<?php
$fn = 'videoFile.mp4';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Description: File Transfer');
header('Content-type: video/mp4');
header('Content-Length: '.filesize($fn));
header('Content-disposition: attachment; filename='.$fn);
readfile($fn);
?>
So the button on the website points to this script. PC browsers seem to start the download with no problem. But the main focus of this is for Android phones. When you click to download the file on the default Android Browser, it fails and all it says is "Download Unsuccessful".
Another thing is that on my computer (using Firefox), the download starts and at about 200MB, it just stops. It doesn't show any signs of failure, it just looks like it finished downloading. The actual file size is about 1GB.
I have played around with the content-type quite a bit, hoping that was the problem. I used "video/mpeg" and "application/force-download" and neither of them worked.
Is there something I'm not doing write? Could the 2 problems be related? Should I be going about this a different way? Thanks for any input.
The Android browser does not appear to like Content-disposition: and related headers. I recommend just a plain redirect to the file in question.
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.