I believe I have already tried you suggestion, but when the login script redirects to some page, as specified in the header function, the cookie is still not visible to that page.
Here is a fragment of the code that I used:
if($row = mysql_fetch_array($result)) SetCookie("CID", $row["MemberID"]);
else
SetCookie("CID","0");
mysql_free_result($result);
mysql_close($oConnection);
header("Location: " . $linkFrom);
The variable $linkFrom is a parameter to this login script that identifies the page to which the login script must redirect to.