Please correct the code as follows:
<?php
setcookie("mycookie", "hello", time() + 3600 * 24 * 31, "/", ".example.com");
?>
This slash (/) might trigger both WWW and non WWW and also every page of the site
http://example.com/*, http://www.example.com/*
.