Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome errors while exporting XLS file using PHP

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

like image 502
Stanley Ngumo Avatar asked May 28 '12 09:05

Stanley Ngumo


2 Answers

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.

like image 141
Stanley Ngumo Avatar answered Sep 30 '22 20:09

Stanley Ngumo


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.

like image 40
Josef Sábl Avatar answered Sep 30 '22 20:09

Josef Sábl