Cookies have to be the first thing in your program that gets sent to the browser, including blank spaces. What I did (I've got a login routine that uses cookies) was separate the entire routine into different files:
login.php3 - enter name/pass
check.php3 - check the name/pass against db (can be done in login.php3)
setcookie.php3 - sets the cookie
content.php3 - whatever you're trying to login to
so setcookie.php3 should look like this:
<?php
setcookie("cookiename", "$cookieval", time()+14400, "/", "www.mydomain.com", 0);
and then to redirect, right underneath that...
header(location: /content.php3);
?>
thats how I did it, anyway.
good luck,
--Intaglio
Gurutech.org