More on my XML/RSS feeds not rendering Jun06 '05

To follow up with my XML rendering problem, I did some more research on Content-Type headers, Apache, PHP, and XML.

Content–Type and headers

I discovered that, by default, PHP pages (.php) are displayed as text/html.

When I say "displayed as...," I am referring to what the browser interprets the page to be. In other words, if the browser sees a header of text/html, it knows to expect HTML code, and it renders the page appropriately.

An XML file (.xml) must be displayed as either text/xml, application/xml, application/xhtml+xml, or a few others I can’t recall right now.

Apache AddType

My problem is that requests (on my server) for XML/RSS files are treated as PHP – because if they weren’t, I wouldn’t be able to dynamically gather their content. And that would make the RSS files useless.

The code that treats XML files as PHP is this:

AddType php-cgi .xml

This is certainly a small code addition, for such a valuable commodity.

However, it presents a slight "catch 22."

In order to utilize dynamic content, my XML file must be treated as PHP. But... in order for the browser to render the XML correctly, it must be treated as XML.

Possible solution

Despite the fact that my XML files are being treated as PHP (via Apache AddType) - they can still be rendered as XML, by specifying the appropriate Content–Type, or header.

This is done by using the PHP header() function:

<?php header('Content-type: text/xml'); ?>

If this call is specified before any other output, your XML file (although treated as PHP), will still render as XML.

You’ll possibly hear more from me

I am still working out some "kinks," with my own CMS, so I have yet to get this working properly.

Hopefully, I will soon.

If not, you know you’ll hear more from me, on this subject!

Categories: Apache , PHP , RSS

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

119 unique visits since August 2008

Syndicate

Advertisements