KBD

Keith Devens .com

Monday, September 8, 2008 Flag waving
"Fools! Don't they know that tears are a woman's most effective weapon?" – Catwoman (The Batman TV Series, episode 83)
← HTTP caching and EtagsWeb specifications have become too complex →

Daily link icon Friday, May 14, 2004

Oh great, the (X)HTML validator is broken! Update: no it's not, Mozilla's view source is broken!

Oh great, the (X)HTML validator is broken. I use a variation of Mark Pilgrim's code to check if the user-agent supports 'application/xhtml+xml':

<?php
if(strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') !== false)
    
header("Content-type: application/xhtml+xml");
else
    
header("Content-type: text/html");
?>

The validator must not be sending an 'application/xhtml+xml' Accept header, because my page is being returned as text/html. The validator then complains that I have no DOCTYPE declaration, even though I'm using one of the declarations included in their list. If I unconditionally return the page with an 'application/xhtml+xml' Content-type, the validator correctly validates the page. What's going on here?

Update: It turns out there's an error in Mozilla's "view source" feature! I couldn't figure out why my page wasn't validating. I tried validating Simon's page, which validated. I finally checked the "show source" feature of the validator, and it turned out I was getting the following PHP notice (reformatted slightly):

<br />
<b>Notice</b>: Undefined index: HTTP_ACCEPT
   in <b>[filename]</b> on line <b>2</b><br />

which Mozilla's "view source" didn't show! It just showed three blank lines at the top of the page. It turns out that the validator doesn't send any Accept header at all, so I changed the above code to (reformatted slightly):

<?php
if(isset($_SERVER['HTTP_ACCEPT']) and
    
strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') !== false)
    
header("Content-type: application/xhtml+xml");
else
    
header("Content-type: text/html");
?>

And that made it work.


I've almost decided that viewing PHP's notices are more trouble than they're worth. Any code I release should be developed with as strict a level of error messages as possible, but there's no reason I should have to put up with it in my code if I don't want to. Though, it's not clear how to develop with strict errors on without all my pages having that level of error messages.

Update: Maybe rather than going straight to 'text/html' I should be going to something like 'text/xml' first.

← HTTP caching and EtagsWeb specifications have become too complex →

Comments XML gif

Keith (http://keithdevens.com/) wrote:

Testing comment posting to make sure I still validate.

Keith | 14-May-2004 4:06am est | http://keithdevens.com/ | #4581

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

September 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
282930 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 7 posts

Recent comments XML

new⇒Girls, please don't get breast implants

I got implants this year and it was​the biggest mistake I ever made.  I​am ...

75.156.208.88: Sep 7, 8:03pm

Trogdor tattoo!!

Oh, so cute, wowoowow....

Kathy Mead: Sep 7, 6:07am

I hate Norton Antivirus

Long long live AVG I love you!...

kevin sands: Sep 6, 7:31pm

I hate ASP.NET

CF, why pick that piece of trash?​Cold Confusion. Is it finally​really a OO...

ColdConfusion: Sep 5, 8:36pm

Maps of Iraq

This is for Linda, I will be​visiting that site some time in the​near futur...

Bob: Sep 5, 1:20pm

Spider solitaire

I don't think the question was​necessarily if there are unbeatable​games.  ...

Jared: Sep 4, 12:44pm

Convert Pantone Colors to RGB and Hex - Color Conversion Chart

The colors on those website don't​seem to relate to the pantone data​we hav...

blah: Sep 3, 10:12am

Generated in about 0.482s.

(Used 8 db queries)

mobile phone