The code you provided is correct, the case could be domain or cache route. First validate that the path where you are validating the cookie is correct, the last parameter of setcookie(), which is '/', indicates that the cookie must be valid for the entire domain. read here: https://www.php.net/manual/pt_BR/function.setcookie.php
clear your browser's cache before making these changes to validate that it is not cached.
Also check the settings set in .htaccess on your apache server for cookies. In mod_headers.c disable caching for dynamic pages. Example:
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>
In cPanel, you can check and adjust some settings that may affect how cookies work.
Go to cPanel or whm panel and look in the side search bar for PHP Settings:
In cPanel, look for a section called "Software" or "Software and Services".
Look for an option called "Select PHP Version", "MultiPHP Manager" or something similar. This will allow you to configure PHP options.
Within the PHP options, you should find settings related to cookies and sessions. Look for options like "session.cookie_domain", "session.cookie_secure" and others that may affect the behavior of cookies.
If your website is using HTTPS (SSL), make sure SSL is properly enabled in cPanel. There is often a section called "Security" or "SSL/TLS" that allows you to configure SSL.
In addition to PHP settings, some hosts may offer options to clear the server's cache. This can be useful to ensure that you are working with the latest version of your code.
If you cannot find the necessary settings or if you have specific questions about your server settings in cPanel, check the cpanel forum which is not updated with more details of the tool or its official documentation at the links: Forum Doc1 Doc2