Changing content-type for a single php file

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
MartinW
Forum Newbie
Posts: 4
Joined: Mon Dec 20, 2010 6:01 pm

Changing content-type for a single php file

Post by MartinW »

I was having a problem with a dynamic rss feed I made in php. Everything works with the feed readers I tested it in but when I try to validate it at w3c I get "Feeds should not be served with the "text/html" media type." It says that the mime type should be application/rss+xml or something similar, and that this is only for maximum compatability. I would like my feed to be fully compatibile. When I declare the content-type with the header function in php, it says that the server that my website is hosted on has already sent the content-type header (text/html). My web hoster said I can change the default_mimetype setting in php.ini. My dynamic rss feed has a .php extension. The problem is that I want all the .php files to be served as text/html, but I want this specific file (the rss feed) to be served as application/rss+xml. Is there a way to do this? If I change my extension of my dynamic rss feed to .xml the PHP processor doesn't process the script in the file. I might be able to change the server settings to send .xml files to the PHP processor, but I would prefer it if I could just change the php.ini file so that I can keep everything the same, but just have my rss feed sent as an application/rss+xml document.

Martin
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Changing content-type for a single php file

Post by josh »

If you can make it work in IE that work around breaks the other browsers, run the work around only if the user has IE. How to detect IE? More javascript. Plenty of tutorials on google. "detect internet explorer"
User avatar
sergio-pro
Forum Commoner
Posts: 88
Joined: Sat Dec 27, 2008 12:26 pm

Re: Changing content-type for a single php file

Post by sergio-pro »

Seems like you output something before sending a header.
Server sends headers just before your first output. It can be a whitespace, or header(), setcookie(), session_start() functions.
You can read more about it here for example: http://www.geeklog.net/faqman/index.php?op=view&t=38
Post Reply