We receive this question/problem often enough to warrant a mention here. If you write a PHP script that sets a cookie, or uses the 'header' function in any way, you must either
1) Use output buffering or
2) Set the cookie or other use of the header function BEFORE any output is sent to the browser.

For more information on both of these options: http://us2.php.net/manual/en/function.header.php