Page 1 of 1

Undefined index: HTTP_ACCEPT

PostPosted: Thu Feb 03, 2011 8:06 am
by emaillenin
I am having a download link to an image. When a user clicks this, he will be readirected to page, where I have used PHP readfile function and force download to the user. But this is what is getting downloaded instead of the image.

<br />
<b>Notice</b>: Undefined index: HTTP_ACCEPT in <b>/home2/public_html/library/Tera-WURFL/WurflSupport.php</b> on line <b>63</b><br />
<br />
<b>Fatal error</b>: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent in /home2/public_html/library/Tera-WURFL/WurflSupport.php, line 63' in /home2/public_html/Zend/library/Zend/Controller/Response/Abstract.php:321

Re: Undefined index: HTTP_ACCEPT

PostPosted: Fri Feb 04, 2011 2:11 pm
by kamermans
Hi! The first problem is that the device/browser you are using is not sending an HTTP_ACCEPT field in it's HTTP Request - this is not a show-stopper, which is why a "NOTICE" level error is shown. The second problem is that Zend is throwing an exception because it can't redirect the user after something has been sent to the browser. In this case, the NOTICE error is being sent to the browser and that is what is killing your script. To fix this, make sure you always block error messages in your file download scripts - even if it did work the file would have the error message at the top of it, which is not what you want. To block all but unrecoverable errors, put this at the top of your PHP script:

Code: Select all
error_reporting(E_ERROR);

Re: Undefined index: HTTP_ACCEPT

PostPosted: Fri Feb 04, 2011 2:39 pm
by emaillenin
Thanks for the reply, admin ;) I'll try to fix it.

Re: Undefined index: HTTP_ACCEPT

PostPosted: Fri Feb 04, 2011 2:58 pm
by kamermans
No problem, let me know if you have any more issues!