In PHP, we create a cookie with a setcookie() function. In the function, we specify the key and the contents of the value to be sent to the scanner and also specify how long it will be stored in the browser.

<?php
setcookie ('cookie', 'salute world');
?>

In the example above, we created a cookie called cookie and we made the value salute world. And because we didn’t enter anything as parameter 3, by default the cookie will be deleted when the browser is closed.

If we want the cookie to be deleted at a date we want, we will enable the 3rd parameter. Here is an example of this:

<?php
setcookie ('cookie', 'salute world', time () + (60 * 60 * 24));
?>

Now that we have entered the 3rd time () + (60 * 60 * 24) this parameter in the current time in seconds 60 * 60 * 24 exactly 24 hours that we have added a day.

This means that the cookie we have created expires + 24 hours from now. After 1 day, this cookie will not be sent when you enter the site.