home | web-mapping | data | scripts | bestiary | about | archive

Archive for the 'PHP' Category

setting MIME type with PHP

Sunday, January 21st, 2007

In PHP, the MIME type is set through the header function [note the header function must be called prior to outputting anything to the browser].

To correctly serve XML, call the header function with the following arguments:

header("Content-Type: text/xml; charset=utf-8");

Correctly serving XHTML is a bit more complicated. The $_SERVER array contains the server variables, allowing us to interrogate the Accept HTTP header:

header("Vary: Accept");
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");

more information on serving XHTML

schiller labs is powered by wordpress . dev site and tool shed for emptystreets.net . valid xhtml . valid css