When displaying and using cookies it is important to validate them especially when they are integral to the functionality of the page. Make sure to check to see if the cookie is set before displaying it.
<?php
$var1 = 0;
if (isset($_COOKIE['$test'])) {
$var1 = $_COOKIE['$test'];
}
echo $var1;
?>