Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Detecting XHTML + XML In Browsers, Can it be improved?
mastercomputers
post Dec 11 2005, 02:14 PM
Post #1


PESTICIDAL MANIAC
Group Icon

Group: Members
Posts: 626
Joined: 1-September 04
From: Auckland, New Zealand
Member No.: 27



I have written a script to detect if the mime-type application/xhtml+xml is supported in browsers, yet some browsers that do support this mime-type have to be tested manually so I was wondering whether there was a better method. Something I would rather do is intercept the browser before it decides to download the page instead, is this possible?

Here's the script I wrote, which detects strings from the User Agent, it's just a small snippet of it:

CODE

<?php
// function to test for application/xhtml+xml mime-type support
function CheckXHTML()
{
 // For Robots, Spiders, Validators and other User Agents without displaying any mime-type
 if(!isset($_SERVER['HTTP_ACCEPT']))
   return TRUE;
 // For Browsers that show the mime-type supported
 elseif(strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'xhtml+xml'))
 // Browsers that support it here: Amaya, Epiphany, Firefox, Galeon, Opera
   return TRUE;
 
 // Created an array incase more browsers need to be added.  
 $UA = array('konqueror');
 // Browsers that were tested and found to support it but fails the above: Konqueror
 foreach($UA as $value)
 {
   if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), $value))
     return TRUE;
 }
 // Those User Agents that fail the above
 return FALSE;
 // Browsers that do not support it: IE, Lynx
}
 
if(CheckXHTML())
 echo 'Supported';
else
 // Shows information about the User Agent if not supported.
 echo 'Not Supported<br />'.$_SERVER['HTTP_ACCEPT'].'<br />'.$_SERVER['HTTP_USER_AGENT'];
?>


The main reason for doing this, is because when creating pages in XHTML 1.1, we also have to make sure the header('Content: application/xhtml+xml; charset=utf-8'); is sent, but some browsers do not support this, so far only IE is my concern, but it can still render it using text/html, which is not the correct way to handle this, but as long as the document is still conforming to HTML 4.01 or XHTML 1.0 it should be safe to use text/html and still have the page displayed correctly by that browser, but sending text/html for browsers that support the XHTML mime-type will have slight problems.

Is there a better method than above? Especially if we can intercept the browser before it wants to download the file. e.g. If the browser doesn't support application/xhtml+xml like IE, they would display the download box to download the page, once downloaded and opened, you'd see it's just the XHTML code which can be displayed in IE by giving it an html extension and opening it with IE.

Here's a test page you could test out, which does not use the detection method but is strictly an XHTML 1.1 document, I also added some other things to the header so that the document would be handled better if cached, quite handy to have.

HTML
<?php
// Send XHTML mime-type
header('Content-Type: application/xhtml+xml; charset=utf-8');
// Send Last-Modified, ETag and Expires header, never set for dynamic scripts
header('Last-Modified: '.gmdate('D, d M Y H:i:s T',getlastmod()));
header('ETag: "'.dechex(getmyinode()).'-'.dechex(filesize($_SERVER['SCRIPT_FILENAME'])).'-'.dechex(getlastmod()).'"');
// Expires: time() + days_till_expiration * hours_in_a_day * minutes_in_an_hour * seconds_in_a_minute
header('Expires: '.gmdate('D, d M Y H:i:s T',time()+ 1 * 24 * 60 * 60));
// XML preprocessing string, split in case short_tags are enabled.
echo '<'.'?xml version="1.0" encoding="utf-8"?'.'>'."\n";
?>
<!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" xml:lang="en">
<head>
<title>XHTML 1.1 Test Page</title>
</head>
<body>
<p>
This is just a test. If your browser displays this and does not ask for this page to be downloaded, your browser supports
<acronym title="eXtensible HyperText Markup Language">XHTML</acronym>.
</p>
</body>
</html>


That's it, cheers,


MC
Go to the top of the page
 
+Quote Post
Hercco
post Dec 13 2005, 07:39 AM
Post #2


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228



QUOTE(mastercomputers @ Dec 11 2005, 04:14 PM)
Is there a better method than above?  Especially if we can intercept the browser before it wants to download the file. e.g. If the browser doesn't support application/xhtml+xml like IE, they would display the download box to download the page, once downloaded and opened, you'd see it's just the XHTML code which can be displayed in IE by giving it an html extension and opening it with IE.
*



I can't think of how could it be possible. As far as I'm concerned, there is no way for us to detect whether IE is going to display a download dialogue or not.

And anyways, I see no reason to change that function. It already does what it needs to do. I personally have treated IE issues by detecting if browser just identifies itself as IE and then go for the "works in IE" code. The only exception I do take in account is Opera (because if its relatively big popularity) and any other browser masking itself as IE just has to pay for it tongue.gif
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Converting HTML over to XHTML(13)
  2. Good Book For Learning Xhtml & Css(2)
  3. Understanding Xhtml(8)
  4. Mixing XHTML 1.1 And iFrame(9)
  5. Browsers, In Your Opinion The Best?(14)
  6. Detecting Wirless Networks(12)
  7. Web Browser And Taskbar Problems (web Browser Disappears)(7)
  8. Juggling An Iframe Box With Xhtml Sites(8)
  9. Rss And Xhtml From The Same Data(0)
  10. Help! Pc Not Detecting Video Card(10)
  11. Can Anyone Help Me Detecting 503 Errors In Php Progs ?(5)
  12. Xhtml Js Loading.(6)
  13. Need Help In Developing Internet Application Suite(9)
  14. Xhtml, Javascript, Css And Frames.(0)
  15. A Timeline Of Web Browsers [1991 - Present](3)
  1. The Best Browser For General Use(9)
  2. How I Use Ie Vs. How I Use Firefox Vs. Other Browsers(2)
  3. Windowsxp Is Not Detecting My Dvd Writer Correctly(8)
  4. Help With Java Applet(8)
  5. Browsers Take Much Time To Open(1)
  6. Xhtml Validation With Php In Cgi Mode(0)
  7. Problem With Xhtml Validation(6)
  8. One Click To Copy Script(0)
  9. Php/xhtml Pages(3)
  10. Vulnerability Was Found In All Major Browsers(20)
  11. Help! - Flash & Xhtml Traditional & Strict(7)
  12. Xhtml Tutorial - Introduction(0)
  13. Xhtml Taking Over Html?(9)
  14. My New And Improved Band Site(0)
  15. I Prefer Ie6 Over Other Browsers.(6)


 



- Lo-Fi Version Time is now: 8th October 2008 - 01:55 AM