在它可以访问的一个文件中设置$ _COOKIES ['key'],但在其他文件中无法查询

I have a directory, under it there are two php files index.php, index2.php:

in the index.php:

<?php

$_COOKIE['constant_a']='A';
echo($_COOKIE['constant_a']);   

in the index2.php:

<?php

echo($_COOKIE['constant_a']);

Firstly, I access the http://localhost:63342/htdocs/index.php, the browser will show the A.

but then I input the index2.php, http://localhost:63342/htdocs/index2.php: there print Undefined Error:

Notice: Undefined index: constant_a in /Users/sof/Desktop/htdocs/index.php on line 12

Why it do not shows the A?

You should use setcookie instead of $_COOKIE['constant_a']='A' as:

setcookie('constant_a', 'A');