if语句后无法访问同一页面上设置的cookie

I set a cookie inside php tag on top of the page:

   $cookie_name = "true";
   $cookie_value = "bla";
   setcookie($cookie_name, $cookie_value, "/");
   echo $cookie_name;   // first

   if(isset($_COOKIE["true"]))
   echo $cookie_name;   // second

First echo seems to work fine but I can't echo the second one. It seems as if the if statement is not equaling to true. Can somebody clarify what is going on? Can there be a syntax error? I am new to cookies and trying this on localhost with url api.app.localhost.

Edit#1: Infact replacing first with echo $_COOKIE["true"] also gives blank output. Is syntax wrong?

The third parameter of setcookie indicates the expire time

try this:

setcookie($cookie_name, $cookie_value, time() + 3600); // this expires in 1 hour