PDA

View Full Version : XHTML and PHP


Randy
12-03-2003, 09:38 PM
I want to serve my webpages as XHTML 1.1. They have valid XHTML content, DOCTYPEs, etc. However, the pages have a ".php" extension they are being served up as "application/x-httpd-php". XHTML 1.1 however, must be served as "application/xhtml+xml". How can I fix my situation? Can I just change the mime type of ".php" files? Can I set PHP to parse the ".xhtml" extension? What do you recommend?

Randy
12-04-2003, 06:31 AM
I found a solution :)

I knew that IE has a problem with Content-Type. Here's the code I found.

<?php
if (stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
{
header("Content-Type: application/xhtml+xml; charset=UTF-8");
}
else
{
header("Content-Type: text/html; charset=UTF-8");
}
?>


Mozilla "broadcasts" that it accepts the "application/xhtml+xml" Content-Type, so this script (inserted at the top of each of my pages via an include), checks if it's Mozilla (-flavored). If it is, it gets the correct Content-Type. If it's not, then it gets the bad Content-Type.

:guess :guess :guess

achtungbaby
12-05-2004, 11:20 PM
Can't you also do this with .htaccess?

Randy
12-06-2004, 12:48 PM
If you change the content type of .php files, they won't get parsed by the PHP processor anymore... I tried it.