Setting cookie

<!doctype html> 
<html>   
  <head> 
    <meta charset="UTF-8"> 
    <title>cookie</title> 
  </head> 
<body>
<?php
setcookie("myCookie", 1);
?>
</body> 
</html> 

I have the code above at http://dot.kr/x-test/cookie.php (temperal URL), but it causes an error.

How can I put a cookie name=“myCookie” and value=“1” in the user’s computer without and error?

The error is occurring because your trying to set the cookie while the HTML loads around it which won’t work. Your code should be

<?php
setcookie("myCookie", 1);
?>
<!doctype html> 
<html>   
  <head> 
    <meta charset="UTF-8"> 
    <title>cookie</title> 
  </head> 
<body>
</body> 
</html>

This does not actually gives you the error rather it shows you a warning. There are some functions in PHP which are work properly only if you use them before sending any output to the browser. So like header(), setcookie(), session_start(), etc. functions have to be used before sending any output. Be careful even a single space before the opening first php tag will cause the warning. See the function in manual for more details.