You need to send the cookie BEFORE the headers will sent.
In Wordpress, if you just put that code in your theme html, it will not work.
You need to do something like this in your functions.php file
function checkAccessed(){
if ( !isset($_COOKIE['accessed']) ) {
setcookie('accessed', 'yes', time() + 3600*24*30);
define("ACCESSED", false);
}else{
define("ACCESSED", true);
}
}
add_action("init", "checkAccessed");
and then in your theme html..
<?php if(!ACCESSED){ ?>
<script></script>
<?php } ?>