In the page that checks the login, set the cookie right at the point where you have verified the person's credentials.
example:
<?php
... some code...
if($username == this) && ($password == that) {
// set cookie
SetCookie("name", "value", time()+3600);
... some more code ...
}
If you do the above, make SURE there is no contents (or even a single linebreak) before the beginning <?php tag, because otherwise PHP will complain that output has started before headers can go out.
You can do the three page method, but that's just an additional page and a little more work :-)
-sridhar