You can set a cookie by simply:
$somevalue = "some value you want to persist";
$cookie_expiry = time() + strtotime("+ 3 month");
setcookie("cookiename",$value,$cookie_expiry);
This will set a cookie that lasts 3 months. You would then write your code to update the cookie whenever they visit your site.
You can retrieve the value by accessing $_COOKIE["cookiename"]