...

View Full Version : PHP file being served as application/xhtml+xml



Sman5109
07-10-2007, 10:31 PM
Hello, I have a php file and i want it to be served as application/xhtml+xml.

Heres the file:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>Eli Loewen Designs</title>
<meta name="description" content="Eli Loewen Web Design" />
<?php include('../keywords.php'); ?>
<link href="../stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="all">
<div id="header"></div>
<div id="menu_top"></div>
<div id="menu">
<div id="menu_left"></div>
<div id="menu_divider_1"></div>
<div id="home_active"><a href="../home/" title="Home"></a></div>
<div id="menu_divider_2"></div>
<div id="portfolio"><a href="../portfolio/" title="Portfolio"></a></div>
<div id="menu_divider_3"></div>
<div id="services"><a href="../services/" title="Services"></a></div>
<div id="menu_divider_4"></div>
<div id="blog"><a href="../blog/" title="Blog"></a></div>
<div id="menu_divider_5"></div>
<div id="contact"><a href="../contact/" title="Contact"></a></div>
<div id="menu_divider_6"></div>
<div id="links"><a href="../links/" title="Links"></a></div>
<div id="menu_right"></div>
</div>
<div id="content">
<div id="content_background">
<div id="content_top"></div>
<div id="content_middle">
<h1>Welcome to Eli Loewen Designs </h1>
<p>With over 5 years of web design experience, I have extensive HTML, CSS, etc. knowledge. Every layout/design I make is completely XHTML 1.1 and CSS valid and always encoded with Unicode (UTF-8).</p>
<p>So far, every layout I have made I have done free of cost. My reasoning for this is that I believe that the best things in life are free. In addition, most new, up and coming people who want to make a web site really have no means of paying for stuff online because they are use usually under the age of 18.</p>
<p>Note: For this design and the rest of my works: From now on I am going to stop trying to make my creations work in old browsers (That means if you’re using IE6, this site is going to look bad). If this web site looks bad and you have an outdated browser, then you should upgrade your browser to the latest version. That means if you have IE6 you should upgrade to IE7 or even better, Firefox 2. </p>
<h2>Donate?</h2>
<p>If you would like to donate to this site to help keep this up and running for as long as possible, please use the link below to go to the new donation page.</p>
<p><a href="donation.php">Donation Page</a></p>
</div>
<div id="content_bottom"></div>
</div>
</div>
<div id="footer">
<?php include('../footer.php'); ?>
</div>
</div>
<?php include('../codes.php'); ?>
</body>
</html>

What do i change/add to get it to be served with that MIME type?

Thank you.

croatiankid
07-10-2007, 10:56 PM
You need to change it on your server, so that the Content-Type HTTP header says it's the MIME type you want. I think you can use the PHP header() function/whatever it is, as well as htaccess, and you could easily search for it on the web.

_Aerospace_Eng_
07-10-2007, 11:01 PM
Why did you post this in the html/css forum when this is clearly a php issue?
Make a file called mimetype.php and put this in it

<?php
if(eregi(basename(__FILE__),$_SERVER['REQUEST_URI']))
die('You cannot access this file directly.');
function set_header()
{

$charset = "utf-8";
$mime = "text/html";

if(stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")) {
// if there's a Q value for "application/xhtml+xml" then also
// retrieve the Q value for "text/html"
if(preg_match("/application\/xhtml\+xml;q=0(\.[1-9]+)/i",
$_SERVER["HTTP_ACCEPT"], $matches)) {
$xhtml_q = $matches[1];
if(preg_match("/text\/html;q=0(\.[1-9]+)/i",
$_SERVER["HTTP_ACCEPT"], $matches)) {
$html_q = $matches[1];
// if the Q value for XHTML is greater than or equal to that
// for HTML then use the "application/xhtml+xml" mimetype
if($xhtml_q >= $html_q) {
$mime = "application/xhtml+xml";
}
}
// if there was no Q value, then just use the
// "application/xhtml+xml" mimetype
} else {
$mime = "application/xhtml+xml";
}
}
// output the mime type and prolog type
header("Content-Type: $mime;charset=$charset");
header("Vary: Accept");
}
?>
then on the page you want to have the mimetype add this

include_once('mimetype.php');
set_header();
The browsers that support that mimetype will get it. The browsers that don't support it will get text/html. I would also be careful with this line

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
as its putting IE6 into quirks mode causing some things not to render properly.

Sman5109
07-10-2007, 11:24 PM
Ok ,i did that. The page is at http://www.eliloewen.com/home/new.php, but it is still being served as text/html? What am i doing wrong? :(

Heres the head up.

<?php include_once('mimetype.php');
set_header(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>Eli Loewen Designs</title>
<meta name="description" content="Eli Loewen Web Design" />
<?php include('../keywords.php'); ?>
<link href="../stylesheet.css" rel="stylesheet" type="text/css" />
</head>

_Aerospace_Eng_
07-10-2007, 11:39 PM
Make sure nothing comes before that code including spaces, and new line characters.

Sman5109
07-10-2007, 11:55 PM
Yep, your right, it was a space in the file. But now for some reason the background of the page is messed up. What do i do to fix it?

Also, in the (new) validator, why does it say its being served as text/html?
http://validator-test.w3.org/check?uri=http%3A%2F%2Fwww.eliloewen.com%2Fhome%2Fnew.php

_Aerospace_Eng_
07-10-2007, 11:59 PM
In true XML the background needs to be put on the html element not the body. Its best to put it on both. The validator is getting the text/html mimetype. Read this
http://juicystudio.com/article/content-negotiation.php#php
You know its best to actually read what things tell you. You get to learn on your own.

Sman5109
07-11-2007, 12:51 AM
Ok, thanks very much :) Your a great help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum