Introduction to Working with Cookies in PHP

There is a way to save data directly in the user's browser. This is done using cookies (cookie). Cookies are small pieces of strings that are stored in a special place in the browser. Each cookie has its own name, by which this cookie can be written and read.

Let's see how this is done. To start, let's create two PHP files. In the first file, we will write a cookie, and in the second - read it.

Writing cookies is done using the function setcookie, which takes the name of the cookie as the first parameter, and the value as the second. It is important to note that writing cookies must be done before any output to the screen (similar to sessions).

So, let's write a cookie named test with the value 'abcde' in the file:

test1.php<?php
  setcookie('test', 'abcde');
?>

Now let's read our cookie in the second file. This is done using the array $_COOKIE:

test2.php<?php
  echo $_COOKIE['test']; // will output 'abcde'
?>
Задание 1

Write a cookie in one file, and in another file display it on the screen.