I have a strange problem. I can not create cookies using this code. But if I run the example code using exactly the same syntax the cookies work fine. Here is my code that is not working: <?php $checkbox1= $_POST['check2']; echo $checkbox1; //this line works properly //make cookie setcookie("assign", $checkbox1); setcookie("assign", $checkbox1, time()+3600, ".joe.tolumalaska.com", 1); echo $_COOKIE["assign"]; //this line does not display anything ?> Here is the example code that works fine: <?php $value = 'something from somewhere'; setcookie("TestCookie", $value); //setcookie("TestCookie", $value, time()+3600); /* expire in 1 hour */ setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".joe.tolumalaska.com", 1); ?> <?php // Print an individual cookie echo $_COOKIE["TestCookie"]; //echo $HTTP_COOKIE_VARS["TestCookie"]; // Another way to debug/test is to view all cookies //print_r($_COOKIE); ?>
Cookies must be set before printing anything so you need to get rid of the echo command - check http://php.net/setcookie