Set Cookie Example
if you want to set a cookie then you can easily set the cookie using the setcookie() function. for that, you need to pass three-parameter in this function such as name, value, and expiration time.
$cookie_val = 'abc'; //variable
setcookie("websiteName", $cookie_val, time()+3600, '/', 'xpertphp.com', true, true);
Retrieve Cookie Value
After sent the cookie, you can easily get the cookie using $_COOKIE[‘cookie_name’].
echo 'Your Website Name Is ' . $_COOKIE['websiteName'];
Updating Cookie Value
If you want to update the cookie then just update the cookie’s value and pass inside the function. for that, you can see the below example.
$cookie_val = 'xyz'; //variable
setcookie("websiteName", $cookie_val, time()+3600);
Delete a Cookie
If you want to delete the cookie then just add a negative expiration time.
setcookie("websiteName", "", time()-3600);