In this article, we will explain to you how to use PHP Cookies with example(PHP Cookies Example create Access and Delete). here we give you a simple PHP cookies example. so you can see the below example.
The PHP cookie is a small file that is stored in the client’s browser. It is used to temporarily store data. we will inform you how to use cookies in PHP and how to set cookies, get cookies, and delete cookies with PHP. so you can see our 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 a three-parameter in this function such as name, value, and expiration time.
<?php
$cookie_val = 'abc'; //variable
setcookie("websiteName", $cookie_val, time()+3600, '/', 'xpertphp.com', true, true);
//
?>
After sending the cookie, you can easily get the cookie using $_COOKIE[‘cookie_name’].
echo 'Your Website Name Is ' . $_COOKIE['websiteName'];
If you want to update the cookie then just update the cookie’s value and pass it inside the function. for that, you can see the below example.
$cookie_val = 'xyz'; //variable
setcookie("websiteName", $cookie_val, time()+3600);
If you want to delete the cookie then just add a negative expiration time.
setcookie("websiteName", "", time()-3600);