Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
XML errors when adding HTTP headers
  • Hello, I have a template I've made to render XML, it looks like this: <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
    <Response>
    <Sms><?php echo $message; ?></Sms>
    </Response> When I add headers to the view to declare the content type and control caching like these... header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Fri, 31 Dec 1999 11:59:00 GMT");
    header("Content-type: text/xml"); ... I get a "error on line 2 at column 6: XML declaration allowed only at the start of the document," which only happens when including headers; The template itself has no whitespace above the XML declaration. Any ideas on why this is and if there's a way to add HTTP headers without breaking things?
  • I also don't know why there's broken images in my post.
  • ...or why the header code I listed is completely mangled...
  • You should not use the PHP header() method in FuelPHP. It will output directly and interferes with FuelPHP's view generation system. If you want to add headers to your output, use the set_header() method of the Reponse class to add headers to your response.
  • Even using set_header() or not using anything for setting headers, it seems that Fuel is adding space at the top of the rendered page even when there's no space above or before echoing the xml declaration. This space is causing it to be detected as invalid XML. Not sure how to get around that without dumping the template altogether and doing something else.
  • Just discovered the problem; At the end of my controller, I had a line break after "?>". This seems to affect the template.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion