Pow header

From PlainOldWebserver

Jump to: navigation, search

Back to Top

pow_header()

Replaces or adds outgoing server response headers. Below, Content-Type is a unique header, so it replaces the default text/html. Set-Cookie, on the other hand, adds to other Set-Cookie headers, if any. Any header type can be added.

  <?sjs
     pow_highlight();
     pow_header("Content-Type:   text/plain");
     document.write("OK<br/>OK");
  ?>
  OR to add a header
  <?sjs
     pow_header("X-Header: 123fd1294");
     pow_header("Set-Cookie: session=d1294");
  ?>

User submitted examples

You can change client browser location (redirect to another page) using:

  <?sjs
      pow_header("Location: http://google.com/");
  ?>


To prevent client browser from caching, for example if you are using XMLHttpRequest in your AJAX apps, be sure you send correct headers:

  <?sjs
    pow_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    pow_header("Last-Modified:    "+Date());
    pow_header("Cache-Control: no-cache, must-revalidate");
    pow_header("Pragma: no-cache");
    pow_header("Content-Type: text/html; charset=\"utf-8\"");
  ?>


To serve a gzipped file, for example if you are hosting .svgz files:

  <?sjs
    pow_header("Content-Type: image/svg+xml");
    pow_header("Content-Encoding: gzip");
    var contents = pow_file("example.svgz");
    document.writeln(contents);
  ?>

See also

Personal tools
Navigation