Why cookies and not sessions. Remember that a lot of people will not allow cookies on their systems.
random value
$uidval = md5(uniqid(rand(),1));
And storing it as a cookie valid for 60 seconds
setcookie("uidval", $uidval,time() + 60);
Cookies can not remain valid forever, a duraction of zero means only that it lasts until the browser closes. If you want the cookie to last for a while just give it a big number in addition to the current time.