• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / RSS with PHP – Don’t forget to set the Content-Type

RSS with PHP – Don’t forget to set the Content-Type

Just a quick little post to remind that PHP/Apache sets the content-type header by default to text/html. If you are serving other content, such as an RSS feed, you need to remember to change the content type to the appropriate format.

For an RSS feed, which is in XML format, it probably won’t cause any issues with feed readers, but to on the safe side it’s a good idea to set the content type correctly.

When troubleshooting something that was going wrong the validator told me the following error:

This feed is valid, but interoperability with the widest range 
of feed readers could be improved by implementing the following 
recommendations.

Feeds should not be served with the "text/html" media type

It’s a PHP script that serves this particular feed, and I hadn’t set the content type myself, so it was defaulting to text/html.

To change it to the corect type of text/xml it’s simply a matter of setting the content-type header like so:

header('Content-Type: text/xml');

I made the change, checked the headers were now being served correctly, got the Feedburner validator to check the script again and now it was happy.

Check Out These Related posts:

  1. PHP email validation using the Zend Framework
  2. PHP Date Constants
  3. Dynamically get and set an elements content with jQuery
  4. Update PHP from the command line with YUM

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap