Tuesday 14 August 2018

PHP Headers and Popular Mime Types

Like my Create a Basic Web Service Using PHP, MySQL, XML, and JSON illustrates, even though a file's extension ends in PHP, you can still tell the browser that you're outputting a different content type. Here are a few of the more popular content types used on the internet.

Atom
header('Content-Type: application/atom+xml');
CSS
header('Content-Type: text/css');
Javascript
header('Content-Type: text/javascript');
JPEG Image
header('Content-Type: image/jpeg');
JSON
header('Content-Type: application/json');
PDF
header('Content-Type: application/pdf');
RSS
header('Content-Type: application/rss+xml; charset=ISO-8859-1');
Text (Plain)
header('Content-Type: text/plain');
XML
header('Content-Type: text/xml');
Just because a file ends in .PHP doesn't mean it responds with XHTML -- respond however you'd like!

0 comments:

Post a Comment