8

I've been using a PHP script to export data from my database (mysql) to a XLS file.

While the file export process is working fine on Firefox and IE.

I am getting errors when trying to export using Google Chrome.

The Google Chrome error is

    Duplicate headers received from server

The response from the server contained duplicate headers. This problem is generally the result of a misconfigured website or proxy. Only the website or proxy administrator can fix this issue.

Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple distinct Content-Disposition headers received. This is disallowed to protect against HTTP response splitting attacks.

I need some assistance on this.

Thanks

Stanley Ngumo
  • 4,089
  • 8
  • 44
  • 64
  • There is something wrong with the HTTP response header. Catch the HTTP header using [Fiddler](http://fiddler2.com) and post it here. – flowfree May 28 '12 at 09:20
  • happened to me. fixed it by removing commas from the file name – d-_-b Sep 16 '13 at 18:34
  • 2
    another answer change `header("Content-Disposition: attachment; filename={$file}");` to `header("Content-Disposition: attachment; filename=\"{$file}\"");` – ahmed hamdy Jun 15 '14 at 14:17
  • In my case doing so caused the error described here: http://stackoverflow.com/questions/6530569/chrome-appends-hyphen-to-the-downloaded-csv-file – user3921472 Aug 01 '16 at 12:30

4 Answers4

12

I've found out what my problem was in the header section of the PHP export code. The incorrect and correct lines are as follows:

Incorrect

header("Content-Disposition: attachment;filename=\"".$this->filename."\"");

Correct

header("Content-Disposition: attachment; filename=\"".$this->filename."\"");

The correction being adding a space between attachment; and filename

Hope this helps.

Stanley Ngumo
  • 4,089
  • 8
  • 44
  • 64
9

I had this same problem. However appearing only very rarely. Cause was similar but not quite the same.

Incorrect

header("Content-Disposition: attachment; filename=$filename");

Correct

header("Content-Disposition: attachment; filename=\"$filename\"");

$filename sometimes contained spaces resulting in mentionec Chrome error.

Josef Sábl
  • 7,538
  • 9
  • 54
  • 66
2

I also faced the same problem. While downloading a file having comma in its name it was saying "duplicate headers received" and it is only in chrome. In Firefox it was OK. After that I just changed my code from
header("Content-Disposition: attachment; filename=$myfilename"); to header("Content-Disposition: attachment; filename=\"$myfilename\""); and it worked fine. Hope it will work for you.

  • Thanks, I have 2700 pages and it works in Chrome for about 96% but not the other 4% but it does work in Edge 100% of the time. – Ewen Feb 24 '20 at 05:54
2

Try this may help you, header('Content-Disposition: attachment; filename="'.$file_name.'"');

instead of

header('Content-Disposition: attachment; filename='.$file_name);

SuRa
  • 1,053
  • 9
  • 13