HTTP headers: Manipulating headers

  1. Common headers
  2. HTTP headers
  3. Common PHP Header Functions

The “header()” function in PHP lets you manipulate headers, and this is most commonly how we do it when we need to set headers inside of a PHP script. Browsers give us a way of manipulating the headers they’re storing for the page, in the HEAD of a web document. We use it to set the character set of our newer web pages:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

This tells the browser to replace whatever it has for the Content-Type header and replace it with text/html; charset=UTF-8.

Finally, you can also manipulate headers in the .htaccess file of Apache servers. You can add or change them directly with the “header” directive. There are also directives for commonly-manipulated headers such as Content-Type (AddType) and Location (Redirect, RedirectPermanent, RedirectMatch).

AddType 'text/html; charset=UTF-8' .html

RedirectPermanent /as/ http://www.example.com/antstorm/

Header set Content-Type "text/html; charset=UTF-8"

Header add Timing "Hello Joe. It took %D microseconds for Apache to serve this request."

Header unset Location

For more information, see these pages:

http://php.net/manual/function.header

http://www.w3schools.com/TAGS/att_meta_http_equiv.asp

http://httpd.apache.org/docs/2.2/mod/mod_headers.html

http://httpd.apache.org/docs/2.2/mod/mod_alias.html

http://httpd.apache.org/docs/2.2/mod/mod_mime.html

  1. Common headers
  2. HTTP headers
  3. Common PHP Header Functions