Background
I've needed the header function in php so many times I figured I'd write a tutorial on it. This tutorial should help you do most of the things that the header function is capable of. Simply put, the php header function will send a http header to the browser.
Headers in PHP
If you are using the header function in between the code, you have to use ob_start() in the beginning of the code, because you have to send the headers before you send the content, so ob_start() buffers the code.It's similar to ASP's Response.Buffer = True.
The following steps should teach you most of the things you need to know about php headers.
The http header allows you to send many messages to the browser, the first of these that I'll explain is the location header.
PHP Code:
<?php
header("Location: http://www.go4expert.com");
?>
You can also control the content type that the browser will treat the document as:
PHP Code:
<?php
header("Content-Type: text/css");
?>
You can also force the browser to display the download prompt and have a recommended filename for the download.
PHP Code:
<?php
header("Content-Type: image/jpeg");
header("Content-Disposition: attachment; filename=file.jpg");
?>
You can also send specific errors to the browser using the header function. It's important to remember the different error messages and what they mean.
PHP Code:
<?php
header("HTTP/1.0 404 Not Found");
?>
PHP Code:
<?php
header("Location: http://www.example.com/");
exit;
?>

