I'm not sure why, but the following doesn't seem to work as expected:
<?php
setcookie('my_cookie', $_GET['v'], time() + (86400 * 7));
echo $_COOKIE['my_cookie'];
?>
If you put this in a file on a PHP web server and call it with a query of yourdomain.com/index.php?v=value
. The value only gets printed to the page on the 2nd request. Why not on the 1st?