How to set cookies for uuid

Not sure why you are asking for a script, or what the problem here is. To set a cookie, just use:

if (empty($_COOKIE["uuid"])) {
    $uuid = uniqid();  // or use a real UUID
    setcookie("uuid", $uuid, time()+30*24*60*60, "");
else {
    $uuid = $_COOKIE["uuid"];

Actually you should execute the setcookie once in a while and anyway to have the cookie lifetime refreshed.

Leave a Comment