3.1.14. httpHeaders()

void httpHeaders ( mixed $contentType [, int $cache] )

Sends the HTTP headers to the browser that declare the content-type and document encoding taken from the charset configuration directive. The $contentType parameter may be one of these constants:

  1. OPT_HTML - HTML document.
  2. OPT_XHTML - XHTML document, if it is supported by the browser and has the higher priority than text/html
  3. OPT_FORCE_XHTML - XHTML document always, if the browser supports it.
  4. OPT_XML - XML document.
  5. OPT_WML - WML document (WAP protocol).
  6. OPT_TXT - plain text document.

If no type matches to your preferences, specify it manually. If the debug console is enabled, OPT changes the content-type to text/html in order to be able to add the console code into the output. In this case, the debug console specifies the following type used:

application/xhtml+xml (text/html used for debug purposes)

The optional second parameter decides, whether the proxy servers should cache the content we send (OPT_HTTP_CACHE, default setting) or not (OPT_NO_HTTP_CACHE). We recommend to call the method just after the parser initialization.

Example 3.6. fetch()

<?php
  try
  {
    $tpl = new optClass;
    $tpl -> loadConfig('config.php');
    $tpl -> httpHeaders(OPT_HTML);

    // your code here
  }
  catch(optException $exception)
  {
    optErrorHandler($exception);
  }
?>

Custom content type:

$tpl -> httpHeaders('application/xml+vrml');

Note: this method is not available, if the Header support was removed from the source with OPT Configurator.