Cookie Settings with Cloudflare

After my post https://community.cloudflare.com/t/i-need-to-block-all-my-traffic-for-a-country-but-unblock-some-user-with-a-specified-pattern/225052

i created a new cookie through this code inside my header

but it’s work for the first time(correctly creating the cookie and redirect to homepage) and then stops to working.

How could i solve my issue? I already bypassed the page /enter in which the cookie is made.

currentURL = "https://" . _SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’];

if ( $currentURL == ‘https://www.test.com/enter/’ ) :

setcookie( 'opt_in', from_italy_ok, time()+31556926, '/');
header( "refresh:1;url=https://www.test.com" );
endif;