Jump to content

Recommended Posts

Hi,

 

I've put together a script that allow users to provide a DoB for verification in order to download a file, usually this is a PDF but could be something else. It generally works fine (1 file per user and 1200 files in total) most have been downloaded fine but seems to be causing issues for a handful of users - It seems to be affecting iOS devices using Safari. Does anyone have any idea as to why this might be happening?  The code executed at the time is:

//Define header information
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Cache-Control: no-cache, must-revalidate");
header("Expires: 0");
header('Content-Disposition: attachment; filename="'.basename($filenameGiven).'"');
header('Content-Length: ' . filesize($filenameGiven));
header('Pragma: public');

//Clear system output buffer
flush();

//Read the size of the file
readfile($filenameGiven);

exit;

 

I was having issues with Android before adding the flush() function as there seems to be a bit of debate around its use.

 

I have attached a screenshot of what those users having issues sees.

Thanks in advance,

Paul

Image.jpeg

this is generally a symptom of something being output to the browser prior to the headers. if this is the case, there would be a php error at the headers stating where the output was started at. is php's error_reporting set to E_ALL and log_errors set to ON, preferably in the php.ini on your system, so that php would log all error? if so, check the web servers error log file.

what code is there before the headers? could it be outputting anything to the browser, such as upon an unexpected received value?

also, for the screenshot, for the file in question, if you open the original or a successfully downloaded copy of it, it in your programming editor, does it start with exactly the same characters as in the screenshot?

  • Like 1

Tek'ma'te Jack O'Neill

The only code that should be output at that time is the code above. Any other code is generated inside other sections of an IF statement. display_errors is on but log_errors was off, error_reporting is already set to E_ALL. Have configured a local php.ini as I don't have access to the global one. I another requested a screenshot taken at the top of the page and it does look to be the same as that shown in a text editor, which is odd.

I work in a school and the user reporting this specific issue is a parent who is now unwilling to give further assistance as the were sent the file manually by another member of staff and unfortunately, I cant replicate it myself.

With error logging no on, I may be able to check back and find an error popping in there and eventually find the cause.

Do you have any other suggestions?

Thanks,

Paul

On 7/8/2022 at 3:50 AM, rrafluap said:

unfortunately, I cant replicate it myself

It might just be an issue with their device and not an issue with the code itself.  Have you tried replicating it with a similar device (iOS + Safari)?

If it works for you even with the same type of device, than I'd suggest that something about their setup is either causing the browser to ignore the headers or possibly striping the headers (proxy?) and causing the browser to display the content.

If there were problems with output before the headers you should be seeing a message about it if you have display_errors=on.  However just to be sure, I'd suggest checking the result of the request to ensure the headers are being sent. You may be able to do that using the browsers developer tools, or use curl with the -i flag to request the URL.

 

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.