Yesterday Maggie said her browser (Netscrape 4 on SunOS) was borking on text/xml. So I tried to fix that and, of course, managed to break things that were working before. Phoenix at least seemed to be loading the site normally, but IE was displaying raw XML, and it didn't seem to have any content-type at all. Bother that.
See, what I had before was a simple check for MSIE in the user-agent string; if it was there, set content-type to text/html, otherwise set to text/xml. So when I started adding another browser to check for, I decided I should make it easier to add browsers to check for (path of evil, I know). So there was an error in my code, but even when I fixed it, IE was still displaying raw XML. But I know by this page (which uses the same logic but outputs text/html or text/xml in the body rather than as content-type) that that part of it does work, or should at least. This is the code, if anyone has any great ideas about how to fix it. No, there is no output before the <?php tags, and I can't figure out anything else about the header function that might be the bug.
$broken_browsers = array ("MSIE","Mozilla\/4\.78");
for ($i=0;$i<count($broken_browsers);$i++) {
if (preg_match("/$broken_browsers[$i]/",$_SERVER["HTTP_USER_AGENT"])) {
$broken = 1;
break;
}
}
if ($broken) {
header("Content-type: text/html");
} else {
header("Content-type: text/xml");
}
So now I've gone back to a string of if - else if - else statements, and it seems to work, at least when I request http://www.niceperson.org/index.php, but not http://www.niceperson.org/. I give up! I desperately hope I'm the only one having this problem with my site.
Kevin says:
I'm still just using:
$legacy = strpos($_SERVER['HTTP_USER_AGENT'],"Mozilla/4"); if ($legacy === false) { header("Content-type: application/xhtml+xml"); }I've not had any complaints yet.
Laurabelle says:
Wow, Mark Pilgrim is my hero. HTTP_ACCEPT header. Who knew?